简单代码:
std::ifstream file("file.txt");
std::string line;
while(getline(file,line))
; //exhaust file
//in this sample code, for simplicity assert that the only possible "fail"
//is EOF (which it will always be under normal circumstances).
assert(!file.fail() || file.eof());
assert(file.peek() == EOF); //does this always hold?
最终断言会始终成功吗?
问题改写:EOF之后的位置是否也返回EOF?
文档没有清楚地提到当流已经在 EOF 时 peek() 做了什么,所以我的问题是。