下一个程序有什么问题吗?我希望文件到达结尾。
ifstream file("main.cpp", ios::binary | ios::ate);
if (file) {
//fstream::pos_type size = file.tellg();
file.seekg(100, fstream::cur);
if (file.eof()) {
cout << "eof is true\n";
}
}
fstream 到达文件末尾,但为什么不回显“eof 为真”。
最佳答案
只有当实际读取操作由于到达文件末尾而失败时,eof 位才会被设置(因此 eof() 仅返回 true)。搜索操作(显然)是不够的。
关于c++ - 在cplusplus中使用fstream时,这个程序有什么问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16356197/