【发布时间】:2013-08-03 08:46:22
【问题描述】:
我正在尝试从输入文件中打印,该文件当时只有一组条目,但是当我尝试打印它时,它显示了两次,我不知道为什么。任何帮助,将不胜感激。这是代码
ifstream orders;
int idNum = 0;
int quantity = 0;
double totalCost = 0;
orders.open("processedOrders.dat");
if (orders.is_open())
{
cout << "Order Number" << setw(16) << "Quantity" << setw(22) << "Total Cost" << endl;
while (!orders.eof())
{
orders >> idNum >> quantity >> totalCost;
cout << " " << idNum << setw(18) << quantity << setw(23) << totalCost << endl;
}
orders.close();
}
【问题讨论】:
-
你在 StackOverflow 上搜索过这个吗?
-
while (!orders.eof())不符合你的想法 -
我相信这将阐明您的问题 -> mathbits.com/MathBits/CompSci/Files/End.htm