title: How to truncate a file while it is open with fstream
body: <p>I know it is possible to truncate a file with</p>
  
  <pre><code>std::fstream fs(mypath, std::fstream::out | std::fstream::trunc);
  </code></pre>
  
  <p>but I need to read the file, truncate it, then write new contents all with the same file handle (so the whole operation is atomic). Anyone?</p>