Thread: Usage of badbit and failbit

  1. #1
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138

    Usage of badbit and failbit

    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?

  2. #2
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    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.

  3. #3
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    Thanks.

  4. #4
    Registered User
    Join Date
    May 2003
    Posts
    148
    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.

  5. #5
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    Yup, I had them backwards.

  6. #6
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    Oops, goes to fix code.

Popular pages Recent additions subscribe to a feed