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?
After a failbit is set: When I first call cin.clear() and then cin.ignore(), the
Share
cin.clear()clears the failbit, butcin.ignore()doesn’t.it means that, if the stream is in an invalid state, calling
clear()followed byignore()will reset the state to good, then ignore the next character.On the other hand, calling
ignore()followed byclear()meansignore()will fail, thenclear()will proceed to reset the stream state. So, in that case, the next character will not be ignored.