Not able to write to a file
<p>My programs have been running properly for over a year. Today I copied the files onto a different system and compiled every program.</p>

<p>When I compile and run from Dev-c++ it writes data onto a text file like its supposed to, but when I click on the executable it creates, it does not write data onto the file. Everything else like input/output seems to work.</p>

<p>What procedure have I missed?</p>

<p>Ok i've given the program Full permision but it still does not write.</p>

<p>I'm quite puzzled, atleast if it didn't run when i compile it in the C++ environment i can keep checking my code, but only the .exe does not work, any other suggestions ?</p>

<pre><code> #include &lt;iostream&gt; 
 #include &lt;fstream&gt;
 using namespace std; 
 int main() {  
 ofstream bss2; 
 bss2.open("expat.txt",ios::app);
 bss2 &lt;&lt; 2 ; 
 bss2.close();
 } 
</code></pre>

<p>This is the sample code i tested out.</p>

<p>How do i find the Current working directory ?</p>

<p>Ok i changed a line to </p>

<pre><code>bss2.open("c:\\expat2.txt",ios::app);
</code></pre>

<p>and now it works properly in the exe file.</p>

<p>but there's over 50 files and i prefer i didn't have to spell out the new path to each one, what workaround is there to set the directory to the one previously used ?</p>

<p>update 4 :</p>

<pre><code> #define _POSIX_SOURCE
 #include &lt;unistd.h&gt;
 #undef _POSIX_SOURCE
 #include &lt;stdio.h&gt;

 main() {
   char cwd[256];
   int y;
   if (chdir("/tmp") != 0)
     perror("chdir() error()");
   else {
     if (getcwd(cwd, sizeof(cwd)) == NULL)
       perror("getcwd() error");
     else
       printf("current working directory is: %s\n", cwd);
   }
   scanf(y);
 }
</code></pre>

<p>Ok i used the getcwd() and this is the message it gives me</p>

<p>chdir() error(): No such file or directory</p>

<p>How do i set the directory now.</p>
