file - read the last line twice -


ifstream infile("score.txt", ios::in); int score; while(infile.good()){     infile >> score;     cout << score << endl; } 

i tried read scores file , print them. last score being read twice. tried other condition such while(!infile.eof()), nothing changes. confused this.

the score file looks following: 78 23 43 23 54

the "54" read , printed twice.

try one......

ifstream infile("score.txt",ios::in); int score;  infile >> score; // before loop read 1 time  while(infile.eof()) {  infile >> score;  cout << score << endl; } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -