Is it possible to read an empty string from cin and still get true from cin.good()?

自作多情 提交于 2019-12-01 20:02:12

No, it is not possible. If no characters could be extracted std::ios::failbit is set. [string.io]/3:

If the function extracts no characters, it calls is.setstate(ios::failbit), which may throw ios_base::failure.

And if characters could be extracted they are subsequently appended to the string and thereby make its size non-zero.

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