iostream bug in g++ 2.95

Martin v. Loewis martin@loewis.home.cs.tu-berlin.de
Fri Jan 14 15:12:00 GMT 2000


> Bug report: c++ istream's getline reads more characters than it should...
> according to The C++ Programming Language, 3rd edition (seventh printing),
> by Bjarne Stroustrup, anyway.  Expected behavior is to be able to read the
> double and int from the first line of (the piped-in) test.input, after
> reading off the name.  What happens is the name gets read correctly, but
> the double and the int are barfo.  I think the reason is that the stream's
> failbit is getting set: C++PL doesn't say that it should be set.  Of
> course, it's not the ISO C++ standard, but I don't have a copy of that to
> reference.

Thanks for your bug report. I believe this is not a bug; libstdc++ is
in accordance with the international standard.

27.6.1.3, [lib.istream.unformatted]/17-21 says about getline

# 17 Effects: Extracts characters and stores them into successive
# locations of an array whose first element is designated by s.
# Characters are extracted and stored until one of the following
# occurs:
# 1) end­of­file occurs on the input sequence (in which case the
#    function calls setstate(eofbit));
# 2) c== delimfor the next available input character c(in which case
#    the input character is extracted but not stored);
# 3) n ­ 1 characters are stored (in which case the function calls
#    setstate(failbit)).

# 18 These conditions are tested in the order shown.

# 19 If the function extracts no characters, it calls
# setstate(failbit) (which may throw ios_base::failure
# (27.4.4.3)).290)

# 20 In any case, it then stores a null character (using charT()) into
# the next successive location of the array. 

# 21 Returns: *this.

Hope this helps,
Martin


More information about the Gcc-bugs mailing list