iostream clear()

谁说我不能喝 提交于 2019-12-04 18:12:05

clear is defined like this:

void clear(iostate state = goodbit);

So, effectively, in.clear(); is doing this: in.clear(istream::goodbit); which resets the stream. Calling in.clear(istream::eofbit | istream::failbit); would set both the eofbit and failbit, I doubt that is what you want.

std::cin.clear(std::istream::eofbit | std::istream::failbit);
std::ios_base::iostate state = std::cin.rdstate();
if( state == (std::istream::eofbit | std::istream::failbit))
{
    std::cout << "eofbit and failbit set" << std::endl;
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!