Doc. No.: WG21/N0965=X3J16/96-0147 Date: 9 Jul 1996 Project: C++ Standard Library Reply to: Nathan Myers Repair basic_string<> input/output ---------------------------------- The description of input/output operations in Clause 22 are so broken as to require wholesale replacement. In particular: - the description of operator>> uses an undefined value n - it mentions nonexistent iostream members ipfx and isfx - it doesn't reset the iostream member width after use - it doesn't eat whitespace correctly - it doesn't clear the string before appending - it claims to modify a private iostream member - it uses redundant traits templates in an undefined way - it uses a nonexistent traits member is_whitespace ** Proposed Resolution: In 21.2.1.8.9 [lib.string.io] and in the corresponding prototypes 21.2 [lib.string.classes]: Replace the definition of operator>> applied to basic_istream<> as follows: template basic_istream& operator>>(basic_istream& is, basic_string& str); Effects: Begins by constructing a sentry object k as if by basic_istream::sentry k(is). If bool(k) is true, it calls str.erase() and then extracts characters from is and appends them to str as if by calling str.append(1,c). If is.width() is greater than zero, the maximum number n of characters appended is is.width(); otherwise n is str.max_size(). Characters are extracted and appended until any of the following occurs: -- n characters are stored; -- end-of-file occurs on the input sequence; -- isspace(c,is.getloc()) is true for the next available input character c. After the last character (if any) is extracted, is.width(0) is called and the sentry object k is destroyed. Returns: is ----------- Replace the declaration of operator<< applied to basic_string<> as follows: template basic_ostream& operator<<(basic_ostream& os, const basic_string& str); ---------------- Replace the definition of function getline applied to basic_string with two functions getline as follows: template basic_istream& getline(basic_istream& is, basic_string& str, charT delim); Effects: Begins by constructing a sentry object k as if by basic_istream::sentry k(is). If bool(k) is true, it calls str.erase() and then extracts characters from is and appends them to str as if by calling str.append(1,c). Characters are extracted and appended until any of the following occurs: -- end-of-file occurs on the input sequence (in which case, calls is.setstate(ios_base::eofbit) -- end-of-file occurs on the input sequence (in which case, calls is.setstate(ios_base::eofbit) -- c == delim for the next available input character c (in which case, c is extracted but not appended) (_lib.iostate.flags_) -- str.max_size() characters are stored (in which case, the function calls is.setstate(ios_base::failbit) (_lib.iostate.flags_) The conditions are tested in the order shown. In any case, after the last character is extracted, the sentry object k is destroyed. If the function extracts no characters, it calls is.setstate(ios_base::failbit) which may throw ios_base::failure (_lib.iostate.flags_). Returns: is. and, overloading with getline, template basic_istream& getline(basic_istream& is, basic_string& str); Returns: getline(is,str,is.widen('\n'));