title: How to create a file in a different directory in C++?
body: <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;cstdlib&gt;
  
  int main() {
      std::fstream f1("/tmp/test");
      if (!f1) {
          std::cerr &lt;&lt; "f1 failed\n";
      } else {
          std::cerr &lt;&lt; "f1 success\n";
      }
      FILE *f2 = fopen("/tmp/test", "w+");
      if (!f2) {
          std::cerr &lt;&lt; "f2 failed\n";
      } else {
          std::cerr &lt;&lt; "f2 success\n";
      }
  }
  </code></pre>
  
  <p>Creating a file in /tmp/ doesn't work for me using fstreams but it does with fopen. What could be the problem? (I get f1 failed and f2 success when /tmp/test doesn't already exist)</p>