我试图从一个输入文件打印,当时只有一组条目,但是当我尝试打印它时,它显示了两次,我不知道为什么。任何帮助,将不胜感激。这是代码
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();
}