How are the badbit and failbit different? This sort of leads to my second question. When overloading an input operator, when should one set the badbit instead of the failbit and vice versa?
How are the badbit and failbit different? This sort of leads to my second question. When overloading an input operator, when should one set the badbit instead of the failbit and vice versa?
Bad means a failure in which the underlying stream is still OK. E.g. reading a letter when expecting a number is bad input, but not a serious cause for error.
Fail means a more serious error, potentially one which disrupts the ability to read from the stream at all.
Thanks.
Cat,I think you mixed fail and bad up.
Stroustrup,21.3.3
The difference between the states fail() and bad() is
subtle. When the state is fail() but not also bad(), it is assumed that the stream is uncorrupted
and that no characters have been lost. When the state is bad(), all bets are off.
Yup, I had them backwards.
Oops, goes to fix code.