C++: strange behavior with std::istream or sentry wrap around

微笑、不失礼 提交于 2019-12-06 04:57:21

The problem is that safeGetLine never sets the eof() state for the stream.

When you use std::istream::sentry se(is);, it will try to read whitespace and discover that you are at end-of-file. When you ask it not to look for whitespace, this never happens.

I believe you should add is.setstate(ios_base::eofbit) to the EOF condition for the function.

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