Defect Report: operator>>(istream&, string&) doesn't set failbit

Defect Report: operator>>(istream&, string&) doesn't set failbit

Post by scott snyde » Sun, 06 Feb 2000 04:00:00

Section: [] paragraphs 1-3

Date: Feb 4, 2000

The description of the stream extraction operator for std::string
(section []) 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 [] and [],
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 paragraph 8.)

Proposed Resolution:

Insert new paragraph after paragraph 2 in section

If the function extracts no characters, it calls is.setstate(ios::failbit)
which may throw ios_base::failure (
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]

[              --- Please see the FAQ before posting. ---               ]
[ FAQ:              ]