【发布时间】:2014-10-07 04:11:37
【问题描述】:
我正在尝试使用 eof 和 peek 但两者似乎都没有给我正确的答案。
if (inputFile.fail()) //check for file open failure
{
cout << "Error opening file" << endl;
cout << "Note that the program will halt" << endl;//error prompt
}
else if (inputFile.eof())
{
cout << "File is empty" << endl;
cout << "Note that program will halt" << endl; // error prompt
}
else
{
//run the file
}
使用此方法无法检测到任何空文件。如果我使用 inputFile.peek 而不是 eof 它会将我的好文件变成空文件。
【问题讨论】:
-
您如何使用
peek()?顺便说一句,EOF 标志仅在读取到达文件末尾后设置。 -
哎呀,又错过了这个副本,这些天几乎没有任何问题,没有任何重复的方式
标签: c++ error-handling fstream