title: Create a file at a given path using C++ in Linux
body: <p>I want to create a file at a given path that is relative to the current directory. The following code behaves erratically. I some times see the file created and some times do not. That may be because of the change in the current directory. Here's the code.</p>
  
  <pre><code>//for appending timestamp
  timeval ts;
  gettimeofday(&amp;ts,NULL);
  std::string timestamp = boost::lexical_cast&lt;std::string&gt;(ts.tv_sec);
  //./folder/inner_folder is an existing directory
  std::string filename = "./folder/inner_folder/abc_"+timestamp+ ".csv";
  std::ofstream output_file(filename);
  output_file &lt;&lt; "abc,efg";
  output_file.close();
  </code></pre>
  
  <p>Now, the problem is the file is created only in some cases. That is when I have as a command line argument an input file from the current directory, it works fine. </p>
  
  <pre><code>./program input_file
  </code></pre>
  
  <p>If I have something like this, it does not work</p>
  
  <pre><code>./program ./folder1/input_file
  </code></pre>
  
  <p>I tried giving the full path as an argument for <code>ofstream</code>, I still don't see the files created. </p>
  
  <p>What is the correct way to do this? Thanks</p>