title: Copy file line by line
body: <p>I have a problem with a loop, what i want to do is copy a file, line by line.
  I used this code but it in the output file write one more bracket and one line.</p>
  
  <pre><code>void copyStringNewFile(ifstream&amp; inData,ofstream&amp; outData)
  {
  string x = "";
  
  while (inData)
  {
      getline(inData, x);
      outData &lt;&lt; x &lt;&lt; '\n';
  }
  }
  </code></pre>
  
  <p>Probably i can remove the line: </p>
  
  <pre><code>string x = "";
  </code></pre>
  
  <p>In the while conditions I've tried a few solution:</p>
  
  <pre><code>while (!inData.eof())    // Works similar to while (inData)
  
  while (inData &gt;&gt; x)      // Delete a lot of lines
  </code></pre>
  
  <p>Thank you so much, and if you can explain where eof can be useful (because in loops it seems useless).</p>