Re: C++ programming challenge
On Jun 17, 11:29 am, Ioannis Vranos <ivra...@freemail.gr> wrote:
James Kanze wrote:
On Jun 17, 8:26 am, Bart van Ingen Schenau <b...@ingen.ddns.info>
It's obviously possible to have EOF
when feof()/std::ios::eof() returns false, and depending on the
implementation, it may be possible to have something other than
EOF when std::ios::eof() returns true. (I'm not sure about
feof() in this case.)
I assume you are talking about the return value of getchar().
Or std::istream::get()
I do not think "it may be possible to have something other
than EOF when std::ios::eof() returns true".
If std::istream::get() is called before std::ios::eof(), it's
entirely possible (although admittedly not likely with a
"conventional" implementation---eofbit normally only gets set on
successful input when look-ahead is required, which isn't the
case for std::istream::get().
The important thing to realize is that if std::ios::eof()
returns true, it says nothing about any previous input; all it
means is that the next input will fail (assuming no intervening
seek, etc.). And if it returns false, it's also possible for
the preceding input to have failed (format error, etc.). In
practice, in fact, it makes no sense testing std::ios::eof()
until after you've detected a failure: basically, if
input.fail() && ! input.bad() && ! input.eof(), there was a
format failure. (Regretfully, the reverse isn't true. You can
have input.fail() && input.eof(), and still have a format error,
rather than a true end of file.)
--
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