title: c++ overwrite already opened file
body: <p>I am opening a file with <code>ifstream</code> to check if it exists. Then I close it and open it with <code>ofstream</code> to write to it, and I think setting <code>ios::trunc</code> flag allows me to overwrite it. </p>
  
  <p>However I'd like the ability to keep the file open if it exists, but I used an <code>ifstream</code> to open it so does that mean I can't write to the file till I close and re-open using <code>fstream</code> or <code>ofstream</code>? I didn't use <code>fstream</code> to begin with because that wouldn't tell me if the file was already there or not. </p>