title: Opening a file in append mode but truncating the file
body: <p>I would like to open a file in <code>append</code> mode, but, if the file already exists, override its contents.</p>
  
  <p>I have tried something like this, but this won't work (I don't have much experience with | and &amp; operators, as you can notice):</p>
  
  <pre><code> //does nothing
  _fs.open(_path, std::ios_base::out | std::ios_base::app | std::ios_base::trunc);
  </code></pre>
  
  <p>Then I decided to open the file in <code>out</code> mode and then close it before opening it again but in <code>append</code> mode, but of course this seems a bad programming way to do it:</p>
  
  <pre><code>if(fexists(_path.c_str())){//Checks if the file exists
      _fs.open(_path, std::ios::out);//Overrides the contents
      _fs.close();
  }
  
  _fs.open(_path, std::ios_base::out | std::ios_base::app);
  </code></pre>
  
  <p>Then intuitively I wrote something like this:</p>
  
  <pre><code>_fs.open(_path, std::ios_base::out | std::ios_base::app &amp; std::ios_base::out | std::ios_base::trunc);
  </code></pre>
  
  <p>and now it's working, why?</p>