when have to set the eof flag?

Levente Farkas lfarkas@mindmaker.hu
Wed Jul 25 05:47:00 GMT 2001


hi,
what is the "good" result for this code? (other compilers and c++ libs gives
different result:-)
I try to find the appropriate part from the standard but it's not clear
for me.
------------------------
#include <iostream>
#include <string>
#include <sstream>

int main()
{
  std::string s( "1234" );
  std::istringstream strm( s );
  int i = 0;
  strm >> i;
  //strm >> i >> std::ws;
  std::cout << "string: " << s << "\n"
            << "i: " << i << "\n"
            << "strm: good: " << strm.good() << " eof: " << strm.eof()
            << std::endl;
  return 0;
}
------------------------
the output is:
string: 1234
i: 1234
strm: good: 1 eof: 0
if I switch to the commented line then eof is true. it's ok. but when
have to set the eof flag. since in the above example the stream pointer
point to the and of file (IMHO).

 -- Levente                               "Si vis pacem para bellum!"



More information about the Libstdc++ mailing list