title: C++ ofstream doesn't change mtime
body: <p>Basically I want to do the same thing as the system call touch (create the file if it doesn't exist, update its modification timestamp if it does).</p>
  
  <pre><code>std::string file = ...;
  std::ofstream(file.c_str(), std::ios::app);
  </code></pre>
  
  <p>This will create the file if it doesn't exist. but it won't change the modification time.</p>
  
  <pre><code>std::string file = ...;
  std::ofstream(file.c_str(), std::ios::out);
  </code></pre>
  
  <p>This will create it if it doesn't exist, it'll update the modification time if it does, but it'll also truncate the file, if it exists.</p>
  
  <p>So how do I touch a file?</p>