Files
cppdraft_translate/cppdraft/string/io.md
2025-10-25 03:02:53 +03:00

5.2 KiB
Raw Blame History

[string.io]

27 Strings library [strings]

27.4 String classes [string.classes]

27.4.4 Non-member functions [string.nonmembers]

27.4.4.4 Inserters and extractors [string.io]

🔗

template<class charT, class traits, class Allocator> basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);

1

#

Effects: Behaves as a formatted input function ([istream.formatted.reqmts]).

After constructing a sentry object, if the sentry object returns true when converted to a value of type bool, calls str.erase() and then extracts characters from is and appends them to str as if by callingstr.append(1, c).

Ifis.width() is greater than zero, the maximum number n of characters appended isis.width(); otherwise n isstr.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 characterc.

2

#

After the last character (if any) is extracted,is.width(0) is called and thesentry object is destroyed.

3

#

If the function extracts no characters,ios_base::failbit is set in the input function's local error state before setstate is called.

4

#

Returns: is.

🔗

template<class charT, class traits, class Allocator> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str);

5

#

Effects: Equivalent to: return os << basic_string_view<charT, traits>(str);

🔗

template<class charT, class traits, class Allocator> basic_istream<charT, traits>& getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str, charT delim); template<class charT, class traits, class Allocator> basic_istream<charT, traits>& getline(basic_istream<charT, traits>&& is, basic_string<charT, traits, Allocator>& str, charT delim);

6

#

Effects: Behaves as an unformatted input function ([istream.unformatted]), except that it does not affect the value returned by subsequent calls tobasic_istream<>::gcount().

After constructing a sentry object, if the sentry object returns true when converted to a value of type bool, calls str.erase() and then extracts characters from is and appends them to str as if by callingstr.append(1, c) until any of the following occurs:

end-of-file occurs on the input sequence;

traits::eq(c, delim) for the next available input characterc (in which case,c is extracted but not appended);

str.max_size() characters are stored (in which case,ios_base::failbit is set in the input function's local error state).

7

#

The conditions are tested in the order shown.

In any case, after the last character is extracted, thesentry object is destroyed.

8

#

If the function extracts no characters,ios_base::failbit is set in the input function's local error state before setstate is called.

9

#

Returns: is.

🔗

template<class charT, class traits, class Allocator> basic_istream<charT, traits>& getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str); template<class charT, class traits, class Allocator> basic_istream<charT, traits>& getline(basic_istream<charT, traits>&& is, basic_string<charT, traits, Allocator>& str);

10

#

Returns: getline(is, str, is.widen('\n')).