title: Use a string to specify filepath in C++ (store files in a folder)
body: <p>I am generating hundreds of output files and would like to store them in a folder called OUT in the working directory rather than the working directory itself. Each file is name according to the current iteration. (out1.txt, out2.txt...etc). I have been looking at the documentation for quite a while and trying different things but not having success.  Here is the code. (it is within a loop where k is the iteration number.</p>
  
  <pre><code>char outname[50];
  char filepath[30];
  char iter_str[10];
  sprintf(iter_str,"%d",k)
  strcpy(outname,"out");
  strcat(outname,iter_str);
  strcat(outname,".txt");
  strcpy(filepath,"..\\OUT\\");
  strcat(filepath,outname);
  file = fopen(filepath,"w");
  </code></pre>
  
  <p>Instead of going into the "OUT" folder, it goes into the working directory and names it like this:</p>
  
  <pre><code>..\OUT\out1.txt
  ..\OUT\out2.txt
  ..\OUT\out3.txt
  etc
  </code></pre>
  
  <p>Any suggestions would be much appreciated!</p>
  
  <p>I have now realized that on unix I should have "/" instead of "\". I have done this and have gotten a seg fault. Also a seg fault when using "//".</p>