copying contents of .txt file to a list using ifstream, .eof() not working as expected
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-considered-wrong">Why is iostream::eof inside a loop condition considered wrong?</a>  </p>
</blockquote>



<p>I wrote a basic method to read in a playername and score from a text file and store them in a list. later on in my program i cout'ed the contents of that list and found that the last playerScore is duplicated (but not the playerName). 
For example my .txt file contains</p>

<pre><code>Holly 10
Carl 938
</code></pre>

<p>But my in my console i see</p>

<pre><code>Holly 10
Carl 938
 928
</code></pre>

<p>i ran the debugger and saw that after it had copied the entry for Carl and inserted it into the list the while loop then ran one more time, but only copied the playerScore data into the new list element on the final pass. Could someone explain why and how i could avoid this? (i actually intend to change it to only read in so many lines anyway but it's become a matter of curiosity) Thanks!</p>

<p><strong>method below:</strong></p>

<pre><code>void HighScoresFileManager::ReadFileToList(list&lt; HighScorePair &gt;&amp; listToWriteTo )
{
   //open file to read from..
   ifstream inFileStream("highscores.txt");

   if(inFileStream){
      //while its not end-of-file, write highscorepairs to the passed in list
      while(!inFileStream.eof()){
         HighScorePair newHighScore;
         inFileStream &gt;&gt; newHighScore.playerName &gt;&gt; newHighScore.playerScore;
         listToWriteTo.push_back(newHighScore);
      }
      std::cout &lt;&lt; "Finished reading highscore.txt" &lt;&lt;std::endl;
      inFileStream.close();

   }
   else std::cout &lt;&lt; "Could not open highscores.txt" &lt;&lt; std::endl;
}
</code></pre>
