title: What is the difference between eof(), fail(), bad(), and good() in C++ streams?
body: <p>I am currently learning C++ from the C++ Primer 5th edition. I am confused about the behavior of the methods to check the status of a stream due to seemingly conflicting information. On page 312 it states </p>
  
  <blockquote>
    <p>If any of <code>badbit</code>, <code>failbit</code>, or <code>eofbit</code> are set, then a condition
    that evaluates that stream will fail.</p>
  </blockquote>
  
  <p>On the very next page, it says that <code>s.fail()</code> is </p>
  
  <blockquote>
    <p>true if <code>failbit</code> or <code>badbit</code> in the stream is set</p>
  </blockquote>
  
  <p>and that </p>
  
  <blockquote>
    <p>the code that is executed when we use a stream as a condition is
    equivalent to calling <code>!fail()</code>.</p>
  </blockquote>
  
  <p>This doesn't make sense because any expression that uses <code>fail()</code> should only know about <code>failbit</code> and <code>badbit</code> (since those are what make up <code>fail()</code>'s value) and yet <code>!fail()</code> is equivalent to all <em>three</em> of <code>badbit</code>, <code>failbit</code>, and <code>eofbit</code> being false. </p>
  
  <p>How do these seemingly contradictory statements fit together?</p>