"Bad Bit"

This is a discussion on "Bad Bit" within the C++ Programming forums, part of the General Programming Boards category; I'm currently experimenting around with how to break things within the bits in a stream. As far as I know ...

  1. #1
    Registered User
    Join Date
    Apr 2005

    "Bad Bit"

    I'm currently experimenting around with how to break things within the bits in a stream. As far as I know there are 3 "naughty bits". There is a "fail bit", an "end of file bit" and a "bad bit". As far as I can decipher the "bad bit" is due to a hardware failure. I have tried EVERYTHING that I can think of to try and trip the "bad bit" and I can't seem to accomplish it. Does anybody have any insight?

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    The badbit is set after a system failure affecting the stream. It's not easy to deliberatly provoke it. It's usually not possible to recover from it, so this is an error that should originate a program failure and termination.
    From now on a large part of your life will be spent finding and correcting your own mistakes.
    And if you are lucky and land yourself a good job, a whole lot more time will be spent finding and correcting other people's mistakes.
    That has to be good, no?

    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Write your custom stream insertion/extraction operator and throw an exception from that:
    #include <iostream>
    #include <stdexcept>
    class dummy {};
    ostream & operator << (ostream &, const dummy &)
      throw std::runtime_error("gotcha")<
    int main()
      try {
        std::cout << dummy();
      } catch(std::runtime_error &) {
      bool b = std::cout.fail();
      std::cout << "Failbit: " << b << "\n";
    All the buzzt!

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fopen returning "Bad File Pointer"
    By jprukop in forum C Programming
    Replies: 4
    Last Post: 04-17-2009, 04:01 PM

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