title: C++ read boolean from binary file and failbit
body: <p>I'm facing a problem reading a boolean from a binary file in C++ (visual studio 2015/windows). Before trying to read the boolean the istream is good but after reading the failbit is set while the stream is not eof and the badbit is also not set.</p>
  
  <p>Some documentation on the failbit  states:
  "Returns true in the same cases as bad(), but also in the case that a format error happens, like when an alphabetical character is extracted when we are trying to read an integer number."</p>
  
  <p>Basically I don't understand how reading a boolean from a binary stream can ever fail if the stream is good before and not eof after. My assumption is that since there is only one bit read as a boolean, there is no formatting. Perhaps there are other conditions in which the failbit is set?</p>
  
  <pre><code>void Parser::binary2Record(std::istream&amp; in) {
      bool is_next_booking;
      in &gt;&gt; current_record_;
      in &gt;&gt; is_next_booking;
      Segment segment;
      while (!is_next_booking &amp;&amp; in) {
          in &gt;&gt; segment;
          current_record_.addSegment(segment);
  
          std::cout &lt;&lt; "State of io before reading boolean " &lt;&lt; (in.good() ? "Good" : "Not good") &lt;&lt; std::endl;
  
          in &gt;&gt; is_next_booking;
  
          std::cout &lt;&lt; "State of io good after reading boolean " &lt;&lt; (in.good() ? "Good" : "Not good") &lt;&lt; std::endl;
          std::cout &lt;&lt; "State of io fail after reading boolean " &lt;&lt; (in.fail() ? "fail" : "Not fail") &lt;&lt; std::endl;
          std::cout &lt;&lt; "State of io bad after reading boolean " &lt;&lt; (in.bad() ? "Bad" : "Not Bad") &lt;&lt; std::endl;
          std::cout &lt;&lt; "State of io eof after reading boolean " &lt;&lt; (in.eof() ? "Eof" : "Not eof") &lt;&lt; std::endl;
      }
  }
  
  Output:
  State of io before reading boolean Good
  State of io good after reading boolean Not good
  State of io fail after reading boolean fail
  State of io bad after reading boolean Not Bad
  State of io eof after reading boolean Not eof
  </code></pre>