Re: "inFile" object cannot read EOF
On Jun 8, 8:20 pm, "BobR" <removeBadB...@worldnet.att.net> wrote:
James Kanze wrote in message...
** You can't "read" EOF **, since by definition, a read fails if the
file is at EOF.
So, my docs are wrong?
" Method: int istream::get ()
Read a single character ** (or EOF) ** from the input stream, returning it
(coerced to an unsigned char) as the result. "
Pourly worded. It "tries" to read a single character, returning
the character read, or EOF if it cannot read a character. EOF
is not a character, but a special out of band value. (That's
why get() returns int, and not char.)
You have to try to read something, and then
check whether it failed. After failure, you can check whether
it was due to EOF, or some other reason.
I once did this in some 'test' code:
// std::vector<unsigned char> Image;
while( SomeInFile.peek() != EOF ){
// .... do stuff ....
// Image.push_back( SomeInFile.get() );
// if not reading single chars, need to check stream state.
}
Maybe it will help the OP to see the light. <G>
Yes. That's basically what I recommended at the filebuf level:
peek() simply returns rdbuf()->sgetc() (or EOF, if the rdbuf()
returns a null pointer).
--
James Kanze (Gabi Software) email: james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34