title: Understanding file stream flags/bits
body: <p>I think that I currently don't understand well the mechanisms of the io stream flags. To try to understand that, I will ask questions on two specific examples.</p>
  
  <hr>
  
  <p>The first one concern the open mode.
  For example, for std::ofstream we have :</p>
  
  <pre><code>void open ( const char * filename, ios_base::openmode mode = ios_base::out );
  
  app (append) Set the stream's position indicator to the end of the stream before each output operation.
  ate (at end) Set the stream's position indicator to the end of the stream on opening.
  binary  (binary) Consider stream as binary rather than text.
  in  (input) Allow input operations on the stream.
  out (output) Allow output operations on the stream.
  trunc   (truncate) Any current content is discarded, assuming a length of zero on opening.
  </code></pre>
  
  <p>I have the following questions :</p>
  
  <pre><code>std::ofstream stream;
  
  // Question 1 : Here I don't specify std::ios::out, so why does it work ? :
  stream.open("file.txt", std::ios::binary);
  
  // Question 2 : Here I activate trunc, but how can I deactivate it ?
  stream.open("file.txt", std::ios:binary | std::ios::trunc);
  
  // Question 3 : What would be the result of that ?
  stream.open("file.txt", std::ios::in);
  </code></pre>
  
  <hr>
  
  <p>The second one concern the state flags. Consider the following example :</p>
  
  <pre><code>std::ofstream stream;
  std::cout&lt;&lt;stream.good()&lt;&lt;stream.bad()&lt;&lt;stream.fail()&lt;&lt;stream.eof()&lt;&lt;std::endl;
  stream&lt;&lt;'x';
  std::cout&lt;&lt;stream.good()&lt;&lt;stream.bad()&lt;&lt;stream.fail()&lt;&lt;stream.eof()&lt;&lt;std::endl;
  /* SOMETHING */
  </code></pre>
  
  <p>As no file is opened, the result is :</p>
  
  <pre><code>1000 // &lt;- Good bit is true
  0110 // &lt;- Fail and bad bit are true
  </code></pre>
  
  <p><strong>Question 4 :</strong> what is the piece of code that I can write instead of <code>/* SOMETHING */</code>, to reset the <code>badbit</code> to <code>false</code> and to set the <code>eofbit</code> to <code>true</code> (this operation has no meaning here, but it is just to understand the behaviour of these bits).</p>
  
  <hr>