Topic: Defect Report: operator>>(istream&, string&) doesn't set failbit
Author: scott snyder <snyder@fnal.gov>
Date: 2000/02/05 Raw View
Section: 21.3.7.9 [lib.string.io] paragraphs 1-3
Submitter: Scott Snyder <snyder@fnal.gov>
Date: Feb 4, 2000
The description of the stream extraction operator for std::string
(section 21.3.7.9 [lib.string.io]) does not contain a requirement
that failbit be set in the case that the operator fails to extract
any characters from the input stream.
This implies that the typical construction
std::istream is;
std::string str;
...
while (is >> str) ... ;
(which tests failbit) is not required to terminate at EOF.
Furthermore, this is inconsistent with other extraction operators,
which do include this requirement. (See sections
27.6.1.2 [lib.stream.formatted] and 27.6.1.3 [lib.stream.unformatted],
where this requirement is present, either explictly or implicitly,
for the extraction operators. It is also present explicitly in the
description of getline (istream&, string&, charT) in
section 21.3.7.9 paragraph 8.)
Proposed Resolution:
Insert new paragraph after paragraph 2 in section 21.3.7.9:
If the function extracts no characters, it calls is.setstate(ios::failbit)
which may throw ios_base::failure (27.4.4.3).
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]