EOF after __copy_streambufs
Brad Howes
howes@ll.mit.edu
Tue Oct 9 15:20:00 GMT 2001
Is the EOF after copying streambufs from iss to cout valid (g++ 3.0.1)?
#include <iostream>
#include <strstream>
int
main( int argc, const char* argv[] )
{
const char* data = "first line # comment\n\
second line\n\
# commentary line\n\
last line\n";
std::istrstream iss( data );
std::cout << "Original:" << std::endl << iss.rdbuf();
short state = std::cout.rdstate();
std::cout.clear();
std::cout << "flags: " << std::hex << state << std::endl;
return 0;
}
When run, I get:
Original:
first line # comment
second line
# commentary line
last line
flags: 2
which is indicates that cout's ios::eofbit was set. It gets set by the
__copy_streambufs template function in streambuf.tcc. When the above code is
compiled under Sun's Forte v5, the eofbit does not get set. Which is correct?
Thanks,
Brad
More information about the Libstdc++
mailing list