我有一个格式如下的文本文件:
fa, ha
ID Item Price Amount Cost
2310 3-Ring Binder 6.99 3 20.97
Sales Tax: 1.63
Shipping: 5.00
Total: 27.60
Grand Total: 27.60
Thank you for shopping at the E-Store!
这就是我填充文件的方式:
orderFile << setw(20) << left << "ID" << setw(20) << "Item" << setw(20) << "Price" << setw(20) << "Amount "<< setw(20) << "Cost"<<"\n";
orderFile << setw(20) << id << setw(20) << description << setw(20) << price << setw(20) << amount<< setw(20) << cost<<"\n"<<"\n";
orderFile << setw(60) << right << "Sales Tax:" << setw(20) << fixed << setprecision(2) << saleTax << "\n";
orderFile << setw(60) << "Shipping:" << setw(20) << fixed << setprecision(2) << shipping << "\n"<<"\n";
orderFile << setw(60) << "Total:" << setw(20) << fixed << setprecision(2) << total << "\n"<< "\n";
使用以下代码打印出文件内容后:
string line;
while(getline(orderFile,line))
cout << line;
控制台中的输出与文件的格式不同,打印内容时会忽略一些新行