Reading from a stream til EOF

N

Nick Hounsome

Hendrik Schober said:
FTR, I just found another one:

Sorry - this is wrong.
const std::istream::char_type chEof =
std::istream::traits_type::eof();

Hopefully your compiler will warn you that this is a narrowing assignment.
eof() returns int_type where int_type is required to hold
"all of the valid characters of char_type plus the end-of-file value eof()"
std::string f( std::istream& is )
{
std::string tmp;
std::getline( is, tmp, chEof );

probably gets up to a character that has the same low order bits as EOF.
If EOF is -1 then this will PROBABLY stop at a DEL (0xff) character in the
file.
The behaviour is actuallu undefined.
 
H

Hendrik Schober

Nick Hounsome said:
[...]
Sorry - this is wrong.

Yes, you're right. I just wanted to
post that I had found this out the
hard way... :(

Schobi

--
(e-mail address removed) is never read
I'm Schobi at suespammers dot org

"Sometimes compilers are so much more reasonable than people."
Scott Meyers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,163
Messages
2,570,897
Members
47,436
Latest member
MaxD

Latest Threads

Top