How to detect end-of-file when using getline?
<pre><code>while(getline(fileIn,line))
{

  fileOut &lt;&lt;line&lt;&lt;endl;

}


while(getline(fileIn,line))
{

  if(fileIn.eof())
   break;
  fileOut &lt;&lt;line&lt;&lt;endl;

}
</code></pre>

<p>I have tried both these pieces of code and the second one also reads past end-of-file and does not break. Can anyone tell me why?</p>

<p>I am just reading from a file and writing the lines out.</p>
