Re: Streams eof() and good()
On Apr 19, 4:19 pm, Zeppe
<zeppe.remove.all.this.long.comm...@email.it> wrote:
Adrian wrote:
This code below produces "GOOD" on one platform and "EOF" on the
other.
I expect it to produce "EOF" as the second read would hit the end of
the stream.
Which result is correct?
Implementation defined, but in practice, I find it difficult to
believe that a correct implementation would not set eof.
#include <iostream>
#include <sstream>
int main(int argc, char *argv[])
{
std::stringstream strm("5 4");
int x;
strm >> x;
strm >> x;
if(strm.good())
{
std::cout << "GOOD\n";
}
if(strm.eof())
{
std::cout << "EOF\n";
}
return 0;
}
It should be GOOD. What is the platform in which you are obtaining EOF?
According to what? I would expect EOF, but I don't think the
standard guarantees it.
The real question is what he is actually trying to do. In
practice, ios::good() is of no use what so ever, and ios::eof()
only after input has failed.
--
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