电话会忽略掉failbit的效果吗? [英] Does the failbit effect the call ignore on cin?

查看:139
本文介绍了电话会忽略掉failbit的效果吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

设置failbit后:
当我第一次调用cin.clear()和cin.ignore()时,程序是正确的。
当我第一次调用cin.ignore()和cin.clear()时,忽略似乎不工作,为什么?

After a failbit is set: When I first call cin.clear() and then cin.ignore(), the programe is right. And when I first call cin.ignore() and then cin.clear(), the ignore seems to not work, why?

推荐答案

cin.clear()清除failbit,但 cin.ignore()

cin.clear() clears the failbit, but cin.ignore() doesn't.

这意味着如果流处于无效状态,调用 clear()后跟< c $ c> ignore()会将状态重置为好,然后忽略下一个字符。

it means that, if the stream is in an invalid state, calling clear() followed by ignore() will reset the state to good, then ignore the next character.

另一方面,调用 ignore()后跟 clear()表示失败,则 clear()将继续重置流状态。因此,在这种情况下,下一个字符不会被忽略。

On the other hand, calling ignore() followed by clear() means ignore() will fail, then clear() will proceed to reset the stream state. So, in that case, the next character will not be ignored.

这篇关于电话会忽略掉failbit的效果吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆