Usage of badbit and failbit

This is a discussion on Usage of badbit and failbit within the C++ Programming forums, part of the General Programming Boards category; How are the badbit and failbit different? This sort of leads to my second question. When overloading an input operator, ...

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

    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
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    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,136
    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
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    Yup, I had them backwards.

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

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21