Problem with EOF when determine stream end

送分小仙女□ 提交于 2019-11-28 13:06:16

Do not use feof() or any variants - it is as simple as that. You want it to somehow predict the next read will fail, but that's not what it does - it tells you what the result of the PREVIOUS read was. The correct way to read a file is (in pseudocode):

while( read( file, buffer ) ) {
   do something with buffer
}

In other words, you need to test the result of the read operation. This is true for both C streams and C++ iostreams.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!