infile eof explained.

closed account (ihq4izwU)
while(counter)
{
infile>>word;
count++;
if(word == "..")
break;
}
cout<<"Successfully scanned!";
cout<<"Number of words = "<<count - 1;

*The above code there is my loop for getting the number of words in an ifstream variable. Too bad the users infile still need to have a ".." to end the loop and get the ouput successfully.

--Can you please rephrase the code, so that the loop will terminate if its already the "end of file"?
1
2
while(infile>>word)
   ++counter;
Topic archived. No new replies allowed.