Re: Replacing blank lines in my .txt data file
Carl Barron wrote:
In article
<1156407927.493751.25300@75g2000cwc.googlegroups.com>, kanze
<kanze@gabi-soft.fr> wrote:
Try it. Read from an istringstream initialized with "abc\n",
and then from one initialized with "abc\nxyz". Using just
getline and testing after, there is no way to distinguish
between the two. If you want to be sure, you need the peek()
before.
Well this doesn't test but prints the eof ,fail and bad
conditions in that order. So if in.eof() is true the string
is read without '\n' and [in this implementation] fail() is
false, before the do while loop finally reads and end file
condition.
Interesting. Double checking, the C++98 version of the standard
does say that encountering EOF without having seen a new line
will not cause failbit to be set; this seems a bit odd, since
it is definitly what I would consider a format error. But of
course, this doesn't help us much, at least not formally, since
eofbit can also be set if we've seen the '\n' correctly
(although in this particular case, I can't imagine it happening
in practice).
--
James Kanze kanze.james@neuf.fr
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
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]