Why does std::fstream set the EOF bit the way it does?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I recently ran into a problem caused by using fstream::eof(). I read the following line from here : The function eof() returns true if the end of the associated input file has been reached, false otherwise. and (mistakenly) assumed this meant that if I used fstream::read() and read past the end of the file, the function eof() would tell me. So I did something like this (very generalized): for(int i = 0; i The problem came because of what is explained later on the page linked above (which I failed to read initially, thanks to the misleading