This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

when have to set the eof flag?


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!"


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]