while loop arguement

I need to input a lot of data from three different files and I need to iterate a loop while there is still input in the file stream. So I need the code to look something along these lines:

while(!eof)
{
do stuff in loop
}

OR!!

while(input in file stream)
{
do stuff in loop
}

I'm not sure of the syntax and I'm almost certain the first solution is the way to go. I don't know how to write it in C++
The first approach is generally not the way to do it. The problem is that the eof flag on a stream is not set until after you've made a read attempt on the stream.

The following approach is preferred:
1
2
3
4
5
6
7
  ifstream   ifs ("input.txt");
  string str;

  while (ifs >> str)  // read a string from stream
  {  //  good bit is set (not eof, not error) 
      //  Do something with str
  }


Topic archived. No new replies allowed.