> > Remove the final white space (the new line), and there's a
> > distinct chance that the code won't display the final '6'.
> > See my other post for the correct way to do it. But in any
> > case, don't ever use ios::eof() before an input has failed.
> Can you please explain that to me? I thought that eof flag was
> only set once an attempted read resulted in passing (not
> reaching) the end of file.
No. The eof flag is set anytime the stream sees the end of
file, even in look ahead. All it means is that the next input
is guaranteed to fail. (But if it isn't set, there's no
guarantee that the next input will succeed.)
Of course, even if it were set only if input failed because of
an end of file, you still wouldn't want to use it to control the
loop, as above---if the input were "1 2 x 4 5 6", you'd go into
an endless loop.
James Kanze (GABI Software) email:(E-Mail Removed)
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34