This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: iostream bug in g++ 2.95
- To: dave at cs dot ualberta dot ca
- Subject: Re: iostream bug in g++ 2.95
- From: "Martin v. Loewis" <martin at loewis dot home dot cs dot tu-berlin dot de>
- Date: Sat, 15 Jan 2000 00:09:26 +0100
- CC: gcc-bugs at gcc dot gnu dot org
- References: <Pine.LNX.4.10.9911241918560.16246-101000@lousana.cs.ualberta.ca>
> 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) endoffile 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