title: ofstream (C++) does not create file (permission denied)
body: <p>I'm digging an open source project (Chromium) which is written in c++ and I want to create a file and write to it. BTW, I build the source code using Ninja build system. Here is my code to create a file:</p>
  
  <pre><code>std::ofstream myfile;
  myfile.open("collectedData.txt", std::fstream::out | std::fstream::app);
  if (myfile.is_open()){
      std::cout &lt;&lt; "file is open.\n";
      myfile &lt;&lt; "Hello from Chrome!" ;
      myfile &lt;&lt; "\n" ;
  }else {
      std::cout &lt;&lt; "error -&gt; " &lt;&lt; strerror(errno) &lt;&lt; "\n";
      std::cout &lt;&lt;"file cannot be opened.\n";
  }
  myfile.close();
  </code></pre>
  
  <p>So the problem is that I get permission denied error with this code and it does not create the file. However, when I create a new project (using VS2010) and copy .exe file of the project in the same directory of the Chromium, the code creates the file. So I think there is no problem with the directory permission.  </p>
  
  <p>In addition, I checked the task manager and found several Chrome.exe processes, so I thought maybe it's because of concurrent processes. Then I decided to check this and added <strong>cin</strong> command to the above code (to the new project in VS2010), before closing the file and run concurrent processes (.exe). In this way, I don't close the file and open several instances of it. Surprisingly, all programs successfully can open the file and write to it. </p>
  
  <p>I do not know what to check more, I was wondering if anyone can help me with this.</p>
  
  <p><strong>UPDATE:</strong>
  I found the problem and you can find the solution in the the answer part.</p>