title: How do I find the directory path of a file I created from ofstream in C++?
body: <p>I want to get the directory of a file which I created using ofstream.
  Code I wrote is something like </p>
  
  <pre><code>std::ofstream txt("sample.txt", std::ios::binary);
  </code></pre>
  
  <p>Then I write some things to the txt file, then call txt.close() to close the ofstream. While writing, I want to get the location of the sample.txt file and write it on to sample.txt.
  For example, the directory path would be like this:</p>
  
  <pre><code>/home/usr/Downloads/sample.txt
  </code></pre>
  
  <p>I want to save that whole thing as string so I can write it into sample.txt file. Can anyone help?
  I am using linux to code this, and a universal way to do this would be nice(working on windows, linux, mac etc).</p>