[iostream.format] (original) (raw)

31.7.5 Input streams [input.streams]

31.7.5.1 General [input.streams.general]

The header defines two class templates and a function template that control input from a stream buffer, along with a function template that extracts from stream rvalues.

31.7.5.2 Class template basic_istream [istream]

31.7.5.2.1 General [istream.general]

When a function is specified with a type placeholder of extended-floating-point-type, the implementation provides overloads for all cv-unqualified extended floating-point types ([basic.fundamental]) in lieu of extended-floating-​point-type.

namespace std { template<class charT, class traits = char_traits<charT>> class basic_istream : virtual public basic_ios<charT, traits> { public: using char_type = charT;using int_type = typename traits::int_type;using pos_type = typename traits::pos_type;using off_type = typename traits::off_type;using traits_type = traits;explicit basic_istream(basic_streambuf<charT, traits>* sb);virtual ~basic_istream();class sentry; basic_istream& operator>>(basic_istream& (*pf)(basic_istream&)); basic_istream& operator>>(basic_ios<charT, traits>& (*pf)(basic_ios<charT, traits>&)); basic_istream& operator>>(ios_base& (*pf)(ios_base&)); basic_istream& operator>>(bool& n); basic_istream& operator>>(short& n); basic_istream& operator>>(unsigned short& n); basic_istream& operator>>(int& n); basic_istream& operator>>(unsigned int& n); basic_istream& operator>>(long& n); basic_istream& operator>>(unsigned long& n); basic_istream& operator>>(long long& n); basic_istream& operator>>(unsigned long long& n); basic_istream& operator>>(float& f); basic_istream& operator>>(double& f); basic_istream& operator>>(long double& f); basic_istream& operator>>(extended-floating-point-type& f); basic_istream& operator>>(void*& p); basic_istream& operator>>(basic_streambuf<char_type, traits>* sb); streamsize gcount() const; int_type get(); basic_istream& get(char_type& c); basic_istream& get(char_type* s, streamsize n); basic_istream& get(char_type* s, streamsize n, char_type delim); basic_istream& get(basic_streambuf<char_type, traits>& sb); basic_istream& get(basic_streambuf<char_type, traits>& sb, char_type delim); basic_istream& getline(char_type* s, streamsize n); basic_istream& getline(char_type* s, streamsize n, char_type delim); basic_istream& ignore(streamsize n = 1, int_type delim = traits::eof()); int_type peek(); basic_istream& read (char_type* s, streamsize n); streamsize readsome(char_type* s, streamsize n); basic_istream& putback(char_type c); basic_istream& unget();int sync(); pos_type tellg(); basic_istream& seekg(pos_type); basic_istream& seekg(off_type, ios_base::seekdir);protected: basic_istream(const basic_istream&) = delete; basic_istream(basic_istream&& rhs); basic_istream& operator=(const basic_istream&) = delete; basic_istream& operator=(basic_istream&& rhs);void swap(basic_istream& rhs);};template<class charT, class traits> basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>&, charT&);template<class traits> basic_istream<char, traits>& operator>>(basic_istream<char, traits>&, unsigned char&);template<class traits> basic_istream<char, traits>& operator>>(basic_istream<char, traits>&, signed char&);template<class charT, class traits, size_t N> basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>&, charT(&)[N]);template<class traits, size_t N> basic_istream<char, traits>& operator>>(basic_istream<char, traits>&, unsigned char(&)[N]);template<class traits, size_t N> basic_istream<char, traits>& operator>>(basic_istream<char, traits>&, signed char(&)[N]);}

The class templatebasic_istreamdefines a number of member function signatures that assist in reading and interpreting input from sequences controlled by a stream buffer.

Two groups of member function signatures share common properties: theformatted input functions(orextractors) and theunformatted input functions.Both groups of input functions are described as if they obtain (orextract) inputcharactersby callingrdbuf()->sbumpc()orrdbuf()->sgetc().

They may use other public members ofistream.

31.7.5.2.2 Constructors [istream.cons]

explicit basic_istream(basic_streambuf<charT, traits>* sb);

Effects: Initializes the base class subobject withbasic_ios​::​init(sb) ([basic.ios.cons]).

Postconditions: gcount() == 0.

basic_istream(basic_istream&& rhs);

Effects: Default constructs the base class, copies thegcount() from rhs, callsbasic_ios<charT, traits>​::​move(rhs) to initialize the base class, and sets the gcount() for rhs to 0.

virtual ~basic_istream();

Remarks: Does not perform any operations ofrdbuf().

31.7.5.2.3 Assignment and swap [istream.assign]

basic_istream& operator=(basic_istream&& rhs);

Effects: Equivalent to swap(rhs).

void swap(basic_istream& rhs);

Effects: Calls basic_ios<charT, traits>​::​swap(rhs).

Exchanges the values returned by gcount() andrhs.gcount().

31.7.5.2.4 Class basic_istream​::​sentry [istream.sentry]

namespace std { template<class charT, class traits> class basic_istream<charT, traits>::sentry { bool ok_; public: explicit sentry(basic_istream& is, bool noskipws = false);~sentry();explicit operator bool() const { return ok_; } sentry(const sentry&) = delete; sentry& operator=(const sentry&) = delete;};}

The classsentrydefines a class that is responsible for doing exception safe prefix and suffix operations.

explicit sentry(basic_istream& is, bool noskipws = false);

Effects: Ifis.good()isfalse, calls is.setstate(failbit).

Otherwise, prepares for formatted or unformatted input.

First, ifis.tie()is not a null pointer, the function callsis.tie()->flush()to synchronize the output sequence with any associated external C stream.

Except that this call can be suppressed if the put area ofis.tie()is empty.

Further an implementation is allowed to defer the call toflushuntil a call ofis.rdbuf()->underflow()occurs.

If no such call occurs before thesentryobject is destroyed, the call toflushmay be eliminated entirely.273

If noskipws is zero andis.flags() & ios_base​::​skipwsis nonzero, the function extracts and discards each character as long as the next available input character c is a whitespace character.

Ifis.rdbuf()->sbumpc()oris.rdbuf()->sgetc()returnstraits​::​eof(), the function callssetstate(failbit | eofbit)(which may throwios_base​::​failure).

Remarks: The constructorexplicit sentry(basic_istream& is, bool noskipws = false) uses the currently imbued locale in is, to determine whether the next input character is whitespace or not.

To decide if the character c is a whitespace character, the constructor performs as if it executes the following code fragment:const ctype<charT>& ctype = use_facet<ctype<charT>>(is.getloc());if (ctype.is(ctype.space, c) != 0)

If, after any preparation is completed,is.good()istrue,ok_ != falseotherwise,ok_ == false.

During preparation, the constructor may callsetstate(failbit)(which may throwios_base​::​​failure ([iostate.flags])).274

explicit operator bool() const;

31.7.5.3 Formatted input functions [istream.formatted]

31.7.5.3.1 Common requirements [istream.formatted.reqmts]

Each formatted input function begins execution by constructing an object of type ios_base​::​iostate, termed the local error state, and initializing it to ios_base​::​goodbit.

It then creates an object of classsentrywith thenoskipws(second) argumentfalse.

If thesentryobject returnstrue, when converted to a value of typebool, the function endeavors to obtain the requested input.

Otherwise, if the sentry constructor exits by throwing an exception or if the sentry object produces falsewhen converted to a value of type bool, the function returns without attempting to obtain any input.

If rdbuf()->sbumpc() or rdbuf()->sgetc()returns traits​::​eof(), thenios_base​::​eofbit is set in the local error state and the input function stops trying to obtain the requested input.

If an exception is thrown during input thenios_base​::​badbit is set in the local error state,*this's error state is set to the local error state, and the exception is rethrown if (exceptions() & badbit) != 0.

After extraction is done, the input function calls setstate, which sets *this's error state to the local error state, and may throw an exception.

In any case, the formatted input function destroys thesentryobject.

If no exception has been thrown, it returns*this.

31.7.5.3.2 Arithmetic extractors [istream.formatted.arithmetic]

basic_istream& operator>>(unsigned short& val); basic_istream& operator>>(unsigned int& val); basic_istream& operator>>(long& val); basic_istream& operator>>(unsigned long& val); basic_istream& operator>>(long long& val); basic_istream& operator>>(unsigned long long& val); basic_istream& operator>>(float& val); basic_istream& operator>>(double& val); basic_istream& operator>>(long double& val); basic_istream& operator>>(bool& val); basic_istream& operator>>(void*& val);

As in the case of the inserters, these extractors depend on the locale'snum_get<> object to perform parsing the input stream data.

These extractors behave as formatted input functions (as described in [istream.formatted.reqmts]).

After a sentry object is constructed, the conversion occurs as if performed by the following code fragment, where state represents the input function's local error state:using numget = num_get<charT, istreambuf_iterator<charT, traits>>; use_facet<numget>(loc).get(*this, 0, *this, state, val);

In the above fragment,locstands for the private member of thebasic_iosclass.

[Note 1:

The first argument provides an object of theistreambuf_iteratorclass which is an iterator pointed to an input stream.

It bypasses istreams and uses streambufs directly.

— _end note_]

Classlocalerelies on this type as its interface toistream, so that it does not need to depend directly onistream.

basic_istream& operator>>(short& val);

The conversion occurs as if performed by the following code fragment (using the same notation as for the preceding code fragment):using numget = num_get<charT, istreambuf_iterator<charT, traits>>;long lval; use_facet<numget>(loc).get(*this, 0, *this, state, lval);if (lval < numeric_limits<short>::min()) { state |= ios_base::failbit; val = numeric_limits<short>::min();} else if (numeric_limits<short>::max() < lval) { state |= ios_base::failbit; val = numeric_limits<short>::max();} else val = static_cast<short>(lval);

basic_istream& operator>>(int& val);

The conversion occurs as if performed by the following code fragment (using the same notation as for the preceding code fragment):using numget = num_get<charT, istreambuf_iterator<charT, traits>>;long lval; use_facet<numget>(loc).get(*this, 0, *this, state, lval);if (lval < numeric_limits<int>::min()) { state |= ios_base::failbit; val = numeric_limits<int>::min();} else if (numeric_limits<int>::max() < lval) { state |= ios_base::failbit; val = numeric_limits<int>::max();} else val = static_cast<int>(lval);

basic_istream& operator>>(_extended-floating-point-type_& val);

If the floating-point conversion rank of _extended-floating-point-type_is not less than or equal to that of long double, then an invocation of the operator function is conditionally supported with implementation-defined semantics.

Otherwise, let FP be a standard floating-point type:

The conversion occurs as if performed by the following code fragment (using the same notation as for the preceding code fragment):using numget = num_get<charT, istreambuf_iterator<charT, traits>>; FP fval; use_facet<numget>(loc).get(*this, 0, *this, state, fval);if (fval < -numeric_limits<_extended-floating-point-type_>::max()) { state |= ios_base::failbit; val = -numeric_limits<_extended-floating-point-type_>::max();} else if (numeric_limits<_extended-floating-point-type_>::max() < fval) { state |= ios_base::failbit; val = numeric_limits<_extended-floating-point-type_>::max();} else { val = static_cast<_extended-floating-point-type_>(fval);}

[Note 2:

When the extended floating-point type has a floating-point conversion rank that is not equal to the rank of any standard floating-point type, then double rounding during the conversion can result in inaccurate results.

from_chars can be used in situations where maximum accuracy is important.

— _end note_]

31.7.5.4 Unformatted input functions [istream.unformatted]

Each unformatted input function begins execution by constructing an object of type ios_base​::​iostate, termed the local error state, and initializing it to ios_base​::​goodbit.

It then creates an object of classsentrywith the default argumentnoskipws(second) argumenttrue.

If thesentryobject returnstrue, when converted to a value of typebool, the function endeavors to obtain the requested input.

Otherwise, if the sentry constructor exits by throwing an exception or if the sentry object produces false, when converted to a value of typebool, the function returns without attempting to obtain any input.

In either case the number of extracted characters is set to 0; unformatted input functions taking a character array of nonzero size as an argument shall also store a null character (usingcharT()) in the first location of the array.

If rdbuf()->sbumpc() or rdbuf()->sgetc()returns traits​::​eof(), thenios_base​::​eofbit is set in the local error state and the input function stops trying to obtain the requested input.

If an exception is thrown during input thenios_base​::​badbit is set in the local error state,*this's error state is set to the local error state, and the exception is rethrown if (exceptions() & badbit) != 0.

If no exception has been thrown it stores the number of characters extracted in a member object.

After extraction is done, the input function calls setstate, which sets *this's error state to the local error state, and may throw an exception.

In any event thesentryobject is destroyed before leaving the unformatted input function.

streamsize gcount() const;

Effects: None.

This member function does not behave as an unformatted input function (as described above).

Returns: The number of characters extracted by the last unformatted input member function called for the object.

If the number cannot be represented, returns numeric_limits<streamsize>​::​max().

Effects: Behaves as an unformatted input function (as described above).

After constructing a sentry object, extracts a character c, if one is available.

Otherwise,ios_base​::​failbit is set in the input function's local error state before setstate is called.

Returns: c if available, otherwisetraits​::​eof().

basic_istream& get(char_type& c);

Effects: Behaves as an unformatted input function (as described above).

After constructing a sentry object, extracts a character, if one is available, and assigns it to c.277

Otherwise,ios_base​::​failbit is set in the input function's local error state before setstate is called.

basic_istream& get(char_type* s, streamsize n, char_type delim);

Effects: Behaves as an unformatted input function (as described above).

After constructing a sentry object, extracts characters and stores them into successive locations of an array whose first element is designated bys.278

Characters are extracted and stored until any of the following occurs:

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

In any case, if n is greater than zero it then stores a null character into the next successive location of the array.

basic_istream& get(char_type* s, streamsize n);

Effects: Callsget(s, n, widen('\n')).

Returns: Value returned by the call.

basic_istream& get(basic_streambuf<char_type, traits>& sb, char_type delim);

Effects: Behaves as an unformatted input function (as described above).

After constructing a sentry object, extracts characters and inserts them in the output sequence controlled bysb.

Characters are extracted and inserted until any of the following occurs:

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

basic_istream& get(basic_streambuf<char_type, traits>& sb);

Effects: Callsget(sb, widen('\n')).

Returns: Value returned by the call.

basic_istream& getline(char_type* s, streamsize n, char_type delim);

Effects: Behaves as an unformatted input function (as described above).

After constructing a sentry object, extracts characters and stores them into successive locations of an array whose first element is designated bys.279

Characters are extracted and stored until one of the following occurs:

1. end-of-file occurs on the input sequence;
2. traits​::​eq(c, delim)for the next available input character c(in which case the input character is extracted but not stored);280
3. n is less than one or n - 1characters are stored (in which case the function callssetstate(​failbit)).

These conditions are tested in the order shown.281

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

In any case, if n is greater than zero, it then stores a null character (usingcharT()) into the next successive location of the array.

[Example 1: #include <iostream> int main() { using namespace std;const int line_buffer_size = 100;char buffer[line_buffer_size];int line_number = 0;while (cin.getline(buffer, line_buffer_size, '\n') || cin.gcount()) { int count = cin.gcount();if (cin.eof()) cout << "Partial final line"; else if (cin.fail()) { cout << "Partial long line"; cin.clear(cin.rdstate() & ~ios_base::failbit);} else { count--; cout << "Line " << ++line_number;} cout << " (" << count << " chars): " << buffer << endl;} } — _end example_]

basic_istream& getline(char_type* s, streamsize n);

Returns: getline(s, n, widen('\n'))

basic_istream& ignore(streamsize n = 1, int_type delim = traits::eof());

Effects: Behaves as an unformatted input function (as described above).

After constructing a sentry object, extracts characters and discards them.

Characters are extracted until any of the following occurs:

[Note 1:

The last condition will never occur iftraits​::​eq_int_type(delim, traits​::​eof()).

— _end note_]

Effects: Behaves as an unformatted input function (as described above).

After constructing a sentry object, reads but does not extract the current input character.

Returns: traits​::​eof()ifgood()isfalse.

Otherwise, returnsrdbuf()->sgetc().

basic_istream& read(char_type* s, streamsize n);

Effects: Behaves as an unformatted input function (as described above).

After constructing a sentry object, if!good()callssetstate(failbit)which may throw an exception, and return.

Otherwise extracts characters and stores them into successive locations of an array whose first element is designated bys.283

Characters are extracted and stored until either of the following occurs:

streamsize readsome(char_type* s, streamsize n);

Effects: Behaves as an unformatted input function (as described above).

After constructing a sentry object, if!good()callssetstate(failbit)which may throw an exception, and return.

Otherwise extracts characters and stores them into successive locations of an array whose first element is designated bys.

Ifrdbuf()->in_avail() == -1, callssetstate(eofbit)(which may throwios_base​::​failure ([iostate.flags])), and extracts no characters;

Returns: The number of characters extracted.

basic_istream& putback(char_type c);

Effects: Behaves as an unformatted input function (as described above), except that the function first clears eofbit.

After constructing a sentry object, if!good()callssetstate(failbit)which may throw an exception, and return.

Ifrdbuf()is not null, callsrdbuf()->sputbackc(c).

Ifrdbuf()is null, or ifsputbackcreturnstraits​::​eof(), callssetstate(badbit)(which may throwios_base​::​failure ([iostate.flags])).

[Note 2:

This function extracts no characters, so the value returned by the next call togcount()is 0.

— _end note_]

Effects: Behaves as an unformatted input function (as described above), except that the function first clears eofbit.

After constructing a sentry object, if!good()callssetstate(failbit)which may throw an exception, and return.

Ifrdbuf()is not null, callsrdbuf()->sungetc().

Ifrdbuf()is null, or ifsungetcreturnstraits​::​eof(), callssetstate(badbit)(which may throwios_base​::​failure ([iostate.flags])).

[Note 3:

This function extracts no characters, so the value returned by the next call togcount()is 0.

— _end note_]

Effects: Behaves as an unformatted input function (as described above), except that it does not count the number of characters extracted and does not affect the value returned by subsequent calls togcount().

After constructing a sentry object, ifrdbuf()is a null pointer, returns -1.

Otherwise, callsrdbuf()->pubsync()and, if that function returns -1callssetstate(badbit)(which may throwios_base​::​failure ([iostate.flags]), and returns-1.

Otherwise, returns zero.

Effects: Behaves as an unformatted input function (as described above), except that it does not count the number of characters extracted and does not affect the value returned by subsequent calls togcount().

Returns: After constructing a sentry object, iffail() != false, returnspos_type(-1)to indicate failure.

Otherwise, returnsrdbuf()->pubseekoff(0, cur, in).

basic_istream& seekg(pos_type pos);

Effects: Behaves as an unformatted input function (as described above), except that the function first clears eofbit, it does not count the number of characters extracted, and it does not affect the value returned by subsequent calls togcount().

After constructing a sentry object, iffail() != true, executesrdbuf()->pubseekpos(pos, ios_base​::​in).

In case of failure, the function callssetstate(failbit)(which may throwios_base​::​failure).

basic_istream& seekg(off_type off, ios_base::seekdir dir);

Effects: Behaves as an unformatted input function (as described above), except that the function first clears eofbit, does not count the number of characters extracted, and does not affect the value returned by subsequent calls to gcount().

After constructing a sentry object, iffail() != true, executesrdbuf()->pubseekoff(off, dir, ios_base​::​in).

In case of failure, the function calls setstate(​failbit) (which may throwios_base​::​failure).

31.7.5.5 Standard basic_istream manipulators [istream.manip]

Each instantiation of the function template specified in this subclause is a designated addressable function ([namespace.std]).

template<class charT, class traits> basic_istream<charT, traits>& ws(basic_istream<charT, traits>& is);

Effects: Behaves as an unformatted input function, except that it does not count the number of characters extracted and does not affect the value returned by subsequent calls to is.gcount().

After constructing a sentry object extracts characters as long as the next available character c is whitespace or until there are no more characters in the sequence.

Whitespace characters are distinguished with the same criterion as used bysentry​::​sentry.

Ifwsstops extracting characters because there are no more available it setseofbit, but notfailbit.

31.7.5.6 Rvalue stream extraction [istream.rvalue]

template<class Istream, class T> Istream&& operator>>(Istream&& is, T&& x);

Constraints: The expression is >> std​::​forward<T>(x) is well-formed when treated as an unevaluated operand andIstream is publicly and unambiguously derived from ios_base.

Effects: Equivalent to:is >> std::forward<T>(x);return std::move(is);

31.7.5.7 Class template basic_iostream [iostreamclass]

31.7.5.7.1 General [iostreamclass.general]

namespace std { template<class charT, class traits = char_traits<charT>> class basic_iostream: public basic_istream<charT, traits>,public basic_ostream<charT, traits> { public: using char_type = charT;using int_type = typename traits::int_type;using pos_type = typename traits::pos_type;using off_type = typename traits::off_type;using traits_type = traits;explicit basic_iostream(basic_streambuf<charT, traits>* sb);virtual ~basic_iostream();protected: basic_iostream(const basic_iostream&) = delete; basic_iostream(basic_iostream&& rhs); basic_iostream& operator=(const basic_iostream&) = delete; basic_iostream& operator=(basic_iostream&& rhs);void swap(basic_iostream& rhs);};}

The class templatebasic_iostreaminherits a number of functions that allow reading input and writing output to sequences controlled by a stream buffer.

31.7.5.7.2 Constructors [iostream.cons]

explicit basic_iostream(basic_streambuf<charT, traits>* sb);

Effects: Initializes the base class subobjects withbasic_istream<charT, traits>(sb) ([istream]) andbasic_ostream<charT, traits>(sb).

Postconditions: rdbuf() == sbandgcount() == 0.

basic_iostream(basic_iostream&& rhs);

Effects: Move constructs from the rvalue rhs by constructing the basic_istream base class withstd​::​move(rhs).

31.7.5.7.3 Destructor [iostream.dest]

virtual ~basic_iostream();

Remarks: Does not perform any operations onrdbuf().

31.7.5.7.4 Assignment and swap [iostream.assign]

basic_iostream& operator=(basic_iostream&& rhs);

Effects: Equivalent to swap(rhs).

void swap(basic_iostream& rhs);

Effects: Calls basic_istream<charT, traits>​::​swap(rhs).

31.7.6 Output streams [output.streams]

31.7.6.1 General [output.streams.general]

The header defines a class template and several function templates that control output to a stream buffer, along with a function template that inserts into stream rvalues.

31.7.6.2 Class template basic_ostream [ostream]

31.7.6.2.1 General [ostream.general]

When a function has a parameter type extended-floating-point-type, the implementation provides overloads for all cv-unqualified extended floating-point types ([basic.fundamental]).

namespace std { template<class charT, class traits = char_traits<charT>> class basic_ostream : virtual public basic_ios<charT, traits> { public: using char_type = charT;using int_type = typename traits::int_type;using pos_type = typename traits::pos_type;using off_type = typename traits::off_type;using traits_type = traits;explicit basic_ostream(basic_streambuf<char_type, traits>* sb);virtual ~basic_ostream();class sentry; basic_ostream& operator<<(basic_ostream& (*pf)(basic_ostream&)); basic_ostream& operator<<(basic_ios<charT, traits>& (*pf)(basic_ios<charT, traits>&)); basic_ostream& operator<<(ios_base& (*pf)(ios_base&)); basic_ostream& operator<<(bool n); basic_ostream& operator<<(short n); basic_ostream& operator<<(unsigned short n); basic_ostream& operator<<(int n); basic_ostream& operator<<(unsigned int n); basic_ostream& operator<<(long n); basic_ostream& operator<<(unsigned long n); basic_ostream& operator<<(long long n); basic_ostream& operator<<(unsigned long long n); basic_ostream& operator<<(float f); basic_ostream& operator<<(double f); basic_ostream& operator<<(long double f); basic_ostream& operator<<(_extended-floating-point-type_ f); basic_ostream& operator<<(const void* p); basic_ostream& operator<<(const volatile void* p); basic_ostream& operator<<(nullptr_t); basic_ostream& operator<<(basic_streambuf<char_type, traits>* sb); basic_ostream& put(char_type c); basic_ostream& write(const char_type* s, streamsize n); basic_ostream& flush(); pos_type tellp(); basic_ostream& seekp(pos_type); basic_ostream& seekp(off_type, ios_base::seekdir);protected: basic_ostream(const basic_ostream&) = delete; basic_ostream(basic_ostream&& rhs); basic_ostream& operator=(const basic_ostream&) = delete; basic_ostream& operator=(basic_ostream&& rhs);void swap(basic_ostream& rhs);};template<class charT, class traits> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>&, charT);template<class charT, class traits> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>&, char);template<class traits> basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, char);template<class traits> basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, signed char);template<class traits> basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, unsigned char);template<class traits> basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, wchar_t) = delete;template<class traits> basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, char8_t) = delete;template<class traits> basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, char16_t) = delete;template<class traits> basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, char32_t) = delete;template<class traits> basic_ostream<wchar_t, traits>& operator<<(basic_ostream<wchar_t, traits>&, char8_t) = delete;template<class traits> basic_ostream<wchar_t, traits>& operator<<(basic_ostream<wchar_t, traits>&, char16_t) = delete;template<class traits> basic_ostream<wchar_t, traits>& operator<<(basic_ostream<wchar_t, traits>&, char32_t) = delete;template<class charT, class traits> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>&, const charT*);template<class charT, class traits> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>&, const char*);template<class traits> basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, const char*);template<class traits> basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, const signed char*);template<class traits> basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, const unsigned char*);template<class traits> basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, const wchar_t*) = delete;template<class traits> basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, const char8_t*) = delete;template<class traits> basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, const char16_t*) = delete;template<class traits> basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, const char32_t*) = delete;template<class traits> basic_ostream<wchar_t, traits>& operator<<(basic_ostream<wchar_t, traits>&, const char8_t*) = delete;template<class traits> basic_ostream<wchar_t, traits>& operator<<(basic_ostream<wchar_t, traits>&, const char16_t*) = delete;template<class traits> basic_ostream<wchar_t, traits>& operator<<(basic_ostream<wchar_t, traits>&, const char32_t*) = delete;}

The class templatebasic_ostreamdefines a number of member function signatures that assist in formatting and writing output to output sequences controlled by a stream buffer.

Two groups of member function signatures share common properties: theformatted output functions(orinserters) and theunformatted output functions.Both groups of output functions generate (orinsert) outputcharactersby actions equivalent to callingrdbuf()->sputc(int_type).

They may use other public members ofbasic_ostreamexcept that they shall not invoke any virtual members ofrdbuf()exceptoverflow(),xsputn(), andsync().

If one of these called functions throws an exception, then unless explicitly noted otherwise the output function setsbadbitin the error state.

Ifbadbitis set inexceptions(), the output function rethrows the exception without completing its actions, otherwise it does not throw anything and proceeds as if the called function had returned a failure indication.

[Note 1:

The deleted overloads of operator<<prevent formatting characters as integers and strings as pointers.

— _end note_]

31.7.6.2.2 Constructors [ostream.cons]

explicit basic_ostream(basic_streambuf<charT, traits>* sb);

Effects: Initializes the base class subobject withbasic_ios<charT, traits>​::​init(sb) ([basic.ios.cons]).

Postconditions: rdbuf() == sb.

basic_ostream(basic_ostream&& rhs);

Effects: Move constructs from the rvalue rhs.

This is accomplished by default constructing the base class and callingbasic_ios<charT, traits>​::​move(rhs) to initialize the base class.

virtual ~basic_ostream();

Remarks: Does not perform any operations onrdbuf().

31.7.6.2.3 Assignment and swap [ostream.assign]

basic_ostream& operator=(basic_ostream&& rhs);

Effects: Equivalent to swap(rhs).

void swap(basic_ostream& rhs);

Effects: Calls basic_ios<charT, traits>​::​swap(rhs).

31.7.6.2.4 Class basic_ostream​::​sentry [ostream.sentry]

namespace std { template<class charT, class traits> class basic_ostream<charT, traits>::sentry { bool ok_; public: explicit sentry(basic_ostream& os);~sentry();explicit operator bool() const { return ok_; } sentry(const sentry&) = delete; sentry& operator=(const sentry&) = delete;};}

The classsentrydefines a class that is responsible for doing exception safe prefix and suffix operations.

explicit sentry(basic_ostream& os);

Ifos.good()is nonzero, prepares for formatted or unformatted output.

Ifos.tie()is not a null pointer, callsos.tie()->flush().284

If, after any preparation is completed,os.good()istrue,ok_ == trueotherwise,ok_ == false.

During preparation, the constructor may callsetstate(failbit)(which may throwios_base​::​​failure ([iostate.flags])).285

If(os.flags() & ios_base​::​unitbuf) && !uncaught_exceptions() && os.good()istrue, callsos.rdbuf()->pubsync().

If that function returns , sets badbit inos.rdstate() without propagating an exception.

explicit operator bool() const;

31.7.6.2.5 Seek members [ostream.seeks]

Each seek member function begins execution by constructing an object of class sentry.

It returns by destroying the sentry object.

Returns: Iffail() != false, returnspos_type(-1)to indicate failure.

Otherwise, returnsrdbuf()->​pubseekoff(​0, cur, out).

basic_ostream& seekp(pos_type pos);

Effects: Iffail() != true, executesrdbuf()->pubseekpos(pos, ios_base​::​out).

In case of failure, the function callssetstate(failbit)(which may throwios_base​::​failure).

basic_ostream& seekp(off_type off, ios_base::seekdir dir);

Effects: Iffail() != true, executesrdbuf()->pubseekoff(off, dir, ios_base​::​out).

In case of failure, the function calls setstate(failbit)(which may throw ios_base​::​failure).

31.7.6.3 Formatted output functions [ostream.formatted]

31.7.6.3.1 Common requirements [ostream.formatted.reqmts]

Each formatted output function begins execution by constructing an object of classsentry.

If that object returnstruewhen converted to a value of typebool, the function endeavors to generate the requested output.

If the generation fails, then the formatted output function doessetstate(ios_base​::​failbit), which can throw an exception.

If an exception is thrown during output, thenios_base​::​badbitis set286in*this's error state.

If(exceptions() & badbit) != 0then the exception is rethrown.

Whether or not an exception is thrown, thesentryobject is destroyed before leaving the formatted output function.

If no exception is thrown, the result of the formatted output function is*this.

The descriptions of the individual formatted output functions describe how they perform output and do not mention thesentryobject.

If a formatted output function of a stream os determines padding, it does so as follows.

Given a charT character sequence seq wherecharT is the character container type of the stream, if the length of seq is less than os.width(), then enough copies ofos.fill() are added to this sequence as necessary to pad to a width of os.width() characters.

If(os.flags() & ios_base​::​adjustfield) == ios_base​::​left istrue, the fill characters are placed after the character sequence; otherwise, they are placed before the character sequence.

31.7.6.3.2 Arithmetic inserters [ostream.inserters.arithmetic]

basic_ostream& operator<<(bool val); basic_ostream& operator<<(short val); basic_ostream& operator<<(unsigned short val); basic_ostream& operator<<(int val); basic_ostream& operator<<(unsigned int val); basic_ostream& operator<<(long val); basic_ostream& operator<<(unsigned long val); basic_ostream& operator<<(long long val); basic_ostream& operator<<(unsigned long long val); basic_ostream& operator<<(float val); basic_ostream& operator<<(double val); basic_ostream& operator<<(long double val); basic_ostream& operator<<(const void* val);

Effects: The classesnum_get<>andnum_put<>handle locale-dependent numeric formatting and parsing.

These inserter functions use the imbuedlocalevalue to perform numeric formatting.

When valis of typebool,long,unsigned long,long long, unsigned long long,double,long double, orconst void*, the formatting conversion occurs as if it performed the following code fragment:bool failed = use_facet<num_put<charT, ostreambuf_iterator<charT, traits>>>( getloc()).put(*this, *this, fill(), val).failed();

When val is of typeshortthe formatting conversion occurs as if it performed the following code fragment:ios_base::fmtflags baseflags = ios_base::flags() & ios_base::basefield;bool failed = use_facet<num_put<charT, ostreambuf_iterator<charT, traits>>>( getloc()).put(*this, *this, fill(), baseflags == ios_base::oct || baseflags == ios_base::hex? static_cast<long>(static_cast<unsigned short>(val)) : static_cast<long>(val)).failed();

When val is of typeintthe formatting conversion occurs as if it performed the following code fragment:ios_base::fmtflags baseflags = ios_base::flags() & ios_base::basefield;bool failed = use_facet<num_put<charT, ostreambuf_iterator<charT, traits>>>( getloc()).put(*this, *this, fill(), baseflags == ios_base::oct || baseflags == ios_base::hex? static_cast<long>(static_cast<unsigned int>(val)) : static_cast<long>(val)).failed();

When val is of typeunsigned shortorunsigned intthe formatting conversion occurs as if it performed the following code fragment:bool failed = use_facet<num_put<charT, ostreambuf_iterator<charT, traits>>>( getloc()).put(*this, *this, fill(), static_cast<unsigned long>(val)).failed();

When val is of typefloatthe formatting conversion occurs as if it performed the following code fragment:bool failed = use_facet<num_put<charT, ostreambuf_iterator<charT, traits>>>( getloc()).put(*this, *this, fill(), static_cast<double>(val)).failed();

The first argument provides an object of theostreambuf_iterator<>class which is an iterator for class basic_ostream<>.

It bypassesostreams and usesstreambufs directly.

Classlocalerelies on these types as its interface to iostreams, since for flexibility it has been abstracted away from direct dependence onostream.

The second parameter is a reference to the base class subobject of typeios_base.

It provides formatting specifications such as field width, and a locale from which to obtain other facets.

Iffailedistruethen doessetstate(badbit), which may throw an exception, and returns.

basic_ostream& operator<<(const volatile void* p);

Effects: Equivalent to: return operator<<(const_cast<const void*>(p));

basic_ostream& operator<<(_extended-floating-point-type_ val);

Effects: If the floating-point conversion rank of _extended-floating-point-type_is less than or equal to that of double, the formatting conversion occurs as if it performed the following code fragment:bool failed = use_facet<num_put<charT, ostreambuf_iterator<charT, traits>>>( getloc()).put(*this, *this, fill(), static_cast<double>(val)).failed();

Otherwise, if the floating-point conversion rank of _extended-floating-point-type_is less than or equal to that of long double, the formatting conversion occurs as if it performed the following code fragment:bool failed = use_facet<num_put<charT, ostreambuf_iterator<charT, traits>>>( getloc()).put(*this, *this, fill(), static_cast<long double>(val)).failed();

Otherwise, an invocation of the operator function is conditionally supported with implementation-defined semantics.

If failed is true then does setstate(badbit), which may throw an exception, and returns.

31.7.6.3.3 basic_ostream​::​operator<< [ostream.inserters]

basic_ostream& operator<<(basic_ostream& (*pf)(basic_ostream&));

Effects: None.

Does not behave as a formatted output function (as described in [ostream.formatted.reqmts]).

basic_ostream& operator<<(basic_ios<charT, traits>& (*pf)(basic_ios<charT, traits>&));

Effects: Callspf(*this).

This inserter does not behave as a formatted output function (as described in [ostream.formatted.reqmts]).

basic_ostream& operator<<(ios_base& (*pf)(ios_base&));

Effects: Callspf(*this).

This inserter does not behave as a formatted output function (as described in [ostream.formatted.reqmts]).

basic_ostream& operator<<(basic_streambuf<charT, traits>* sb);

Effects: Behaves as an unformatted output function ([ostream.unformatted]).

After the sentry object is constructed, ifsb is null callssetstate(badbit)(which may throwios_base​::​failure).

Gets characters from sband inserts them in*this.

Characters are read from sband inserted until any of the following occurs:

If the function inserts no characters, it callssetstate(failbit)(which may throwios_base​::​​failure ([iostate.flags])).

If an exception was thrown while extracting a character, the function setsfailbitin the error state, and iffailbitis set inexceptions()the caught exception is rethrown.

basic_ostream& operator<<(nullptr_t);

Effects: Equivalent to:return *this << s;where s is animplementation-definedNTCTS.

31.7.6.3.4 Character inserter function templates [ostream.inserters.character]

template<class charT, class traits> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& out, charT c);template<class charT, class traits> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& out, char c);// specialization template<class traits> basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>& out, char c);// signed and unsigned template<class traits> basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>& out, signed char c);template<class traits> basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>& out, unsigned char c);

Effects: Behaves as a formatted output functionof out.

Constructs a character sequence seq.

If c has typecharand the character container type of the stream is notchar, then seq consists ofout.widen(c); otherwise seq consists ofc.

Determines padding for seq as described in [ostream.formatted.reqmts].

Inserts seq intoout.

Calls os.width(0).

template<class charT, class traits> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& out, const charT* s);template<class charT, class traits> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& out, const char* s);template<class traits> basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>& out, const char* s);template<class traits> basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>& out, const signed char* s);template<class traits> basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>& out,const unsigned char* s);

Preconditions: s is not a null pointer.

Effects: Behaves like a formatted inserter (as described in [ostream.formatted.reqmts]) of out.

Creates a character sequence seq of n characters starting at s, each widened usingout.widen() ([basic.ios.members]), where n is the number that would be computed as if by:

Determines padding for seq as described in [ostream.formatted.reqmts].

Inserts seq intoout.

Calls width(0).

31.7.6.3.5 Print [ostream.formatted.print]

template<class... Args> void print(ostream& os, format_string<Args...> fmt, Args&&... args);

Effects: If the ordinary literal encoding ([lex.charset]) is UTF-8, equivalent to:vprint_unicode(os, fmt.str, make_format_args(args...));

Otherwise, equivalent to:vprint_nonunicode(os, fmt.str, make_format_args(args...));

template<class... Args> void println(ostream& os, format_string<Args...> fmt, Args&&... args);

Effects: Equivalent to:print(os, "{}\n", format(os.getloc(), fmt, std::forward<Args>(args)...));

void println(ostream& os);

Effects: Equivalent to:print(os, "\n");

void vprint_unicode(ostream& os, string_view fmt, format_args args);void vprint_nonunicode(ostream& os, string_view fmt, format_args args);

Effects: Behaves as a formatted output function ([ostream.formatted.reqmts]) of os, except that:

After constructing a sentry object, the function initializes a variable with automatic storage duration viastring out = vformat(os.getloc(), fmt, args);

If writing to the terminal or inserting into os fails, calls os.setstate(ios_base​::​badbit)(which may throw ios_base​::​failure).

Recommended practice: For vprint_unicode, if invoking the native Unicode API requires transcoding, implementations should substitute invalid code units with U+fffd replacement character per the Unicode Standard, Chapter 3.9 U+fffd Substitution in Conversion.

31.7.6.4 Unformatted output functions [ostream.unformatted]

Each unformatted output function begins execution by constructing an object of classsentry.

If that object returnstrue, while converting to a value of typebool, the function endeavors to generate the requested output.

If an exception is thrown during output, thenios_base​::​badbitis set289in*this's error state.

If(exceptions() & badbit) != 0then the exception is rethrown.

In any case, the unformatted output function ends by destroying thesentry object, then, if no exception was thrown, returning the value specified for the unformatted output function.

basic_ostream& put(char_type c);

Effects: Behaves as an unformatted output function (as described above).

After constructing a sentryobject, inserts the character c, if possible.290

Otherwise, callssetstate(badbit)(which may throwios_base​::​failure ([iostate.flags])).

basic_ostream& write(const char_type* s, streamsize n);

Effects: Behaves as an unformatted output function (as described above).

After constructing a sentryobject, obtains characters to insert from successive locations of an array whose first element is designated bys.291

Characters are inserted until either of the following occurs:

Effects: Behaves as an unformatted output function (as described above).

Ifrdbuf()is not a null pointer, constructs a sentry object.

If that object returns true when converted to a value of type bool the function callsrdbuf()->pubsync().

If that function returns callssetstate(badbit)(which may throwios_base​::​failure ([iostate.flags])).

Otherwise, if the sentry object returns false, does nothing.

31.7.6.5 Standard basic_ostream manipulators [ostream.manip]

Each instantiation of any of the function templates specified in this subclause is a designated addressable function ([namespace.std]).

template<class charT, class traits> basic_ostream<charT, traits>& endl(basic_ostream<charT, traits>& os);

Effects: Callsos.put(os.widen('\n')), thenos.flush().

template<class charT, class traits> basic_ostream<charT, traits>& ends(basic_ostream<charT, traits>& os);

Effects: Inserts a null character into the output sequence: callsos.put(charT()).

template<class charT, class traits> basic_ostream<charT, traits>& flush(basic_ostream<charT, traits>& os);

Effects: Callsos.flush().

template<class charT, class traits> basic_ostream<charT, traits>& emit_on_flush(basic_ostream<charT, traits>& os);

Effects: If os.rdbuf() is abasic_syncbuf<charT, traits, Allocator>*, called buf for the purpose of exposition, calls buf->set_emit_on_sync(true).

Otherwise this manipulator has no effect.

[Note 1:

To work around the issue that theAllocator template argument cannot be deduced, implementations can introduce an intermediate base class to basic_syncbuf that manages its emit-on-sync flag.

— _end note_]

template<class charT, class traits> basic_ostream<charT, traits>& noemit_on_flush(basic_ostream<charT, traits>& os);

Effects: If os.rdbuf() is abasic_syncbuf<charT, traits, Allocator>*, called buf for the purpose of exposition, calls buf->set_emit_on_sync(false).

Otherwise this manipulator has no effect.

template<class charT, class traits> basic_ostream<charT, traits>& flush_emit(basic_ostream<charT, traits>& os);

Effects: Calls os.flush().

Then, if os.rdbuf() is abasic_syncbuf<charT, traits, Allocator>*, called buf for the purpose of exposition, behaves as an unformatted output function ([ostream.unformatted]) of os.

After constructing a sentry object, calls buf->emit().

If that call returns false, calls os.setstate(ios_base​::​badbit).

31.7.6.6 Rvalue stream insertion [ostream.rvalue]

template<class Ostream, class T> Ostream&& operator<<(Ostream&& os, const T& x);

Constraints: The expression os << x is well-formed when treated as an unevaluated operand andOstream is publicly and unambiguously derived from ios_base.

Effects: As if by: os << x;

Returns: std​::​move(os).

31.7.7 Standard manipulators [std.manip]

The header defines several functions that support extractors and inserters that alter information maintained by classios_base and its derived classes.

_unspecified_ resetiosflags(ios_base::fmtflags mask);

Returns: An object of unspecified type such that if out is an object of typebasic_ostream<charT, traits> then the expressionout << resetiosflags(mask) behaves as if it calledf(out, mask), or if in is an object of typebasic_istream<charT, traits> then the expressionin >> resetiosflags(​mask) behaves as if it calledf(in, mask), where the function fis defined as:292 void f(ios_base& str, ios_base::fmtflags mask) { str.setf(ios_base::fmtflags(0), mask);}

The expression out << resetiosflags(mask) has type basic_ostream<charT, traits>& and value out.

The expression in >> resetiosflags(mask) has typebasic_istream<charT, traits>& and value in.

_unspecified_ setiosflags(ios_base::fmtflags mask);

Returns: An object of unspecified type such that ifoutis an object of typebasic_ostream<charT, traits>then the expressionout << setiosflags(mask)behaves as if it calledf(out, mask), or ifinis an object of typebasic_istream<charT, traits>then the expressionin >> setiosflags(mask)behaves as if it calledf(in, mask), where the function f is defined as:void f(ios_base& str, ios_base::fmtflags mask) { str.setf(mask);}

The expressionout << setiosflags(mask)has typebasic_ostream<charT, traits>&and valueout.

The expressionin >> setiosflags(mask)has typebasic_istream<charT, traits>&and valuein.

_unspecified_ setbase(int base);

Returns: An object of unspecified type such that ifoutis an object of typebasic_ostream<charT, traits>then the expressionout << setbase(base)behaves as if it calledf(out, base), or ifinis an object of typebasic_istream<charT, traits>then the expressionin >> setbase(base)behaves as if it calledf(in, base), where the function f is defined as:void f(ios_base& str, int base) { str.setf(base == 8 ? ios_base::oct : base == 10 ? ios_base::dec : base == 16 ? ios_base::hex : ios_base::fmtflags(0), ios_base::basefield);}

The expressionout << setbase(base)has typebasic_ostream<charT, traits>&and valueout.

The expressionin >> setbase(base)has typebasic_istream<charT, traits>&and valuein.

_unspecified_ setfill(char_type c);

Returns: An object of unspecified type such that ifoutis an object of typebasic_ostream<charT, traits>and c has typecharTthen the expressionout << setfill(c)behaves as if it calledf(out, c), where the function f is defined as:template<class charT, class traits> void f(basic_ios<charT, traits>& str, charT c) { str.fill(c);}

The expressionout << setfill(c)has typebasic_ostream<charT, traits>&and valueout.

_unspecified_ setprecision(int n);

Returns: An object of unspecified type such that ifoutis an object of typebasic_ostream<charT, traits>then the expressionout << setprecision(n)behaves as if it calledf(out, n), or ifinis an object of typebasic_istream<charT, traits>then the expressionin >> setprecision(n)behaves as if it calledf(in, n), where the function f is defined as:void f(ios_base& str, int n) { str.precision(n);}

The expressionout << setprecision(n)has typebasic_ostream<charT, traits>&and valueout.

The expressionin >> setprecision(n)has typebasic_istream<charT, traits>&and valuein.

Returns: An object of unspecified type such that ifoutis an instance ofbasic_ostream<charT, traits>then the expressionout << setw(n)behaves as if it calledf(out, n), or ifinis an object of typebasic_istream<charT, traits>then the expressionin >> setw(n)behaves as if it calledf(in, n), where the function f is defined as:void f(ios_base& str, int n) { str.width(n);}

The expressionout << setw(n)has typebasic_ostream<charT, traits>&and valueout.

The expressionin >> setw(n)has typebasic_istream<charT, traits>&and valuein.

31.7.8 Extended manipulators [ext.manip]

The header defines several functions that support extractors and inserters that allow for the parsing and formatting of sequences and values for money and time.

template<class moneyT> _unspecified_ get_money(moneyT& mon, bool intl = false);

Mandates: The type moneyT is either long double or a specialization of the basic_string template ([strings]).

Effects: The expression in >> get_money(mon, intl) described below behaves as a formatted input function.

Returns: An object of unspecified type such that ifin is an object of type basic_istream<charT, traits>then the expression in >> get_money(mon, intl) behaves as if it calledf(in, mon, intl), where the function f is defined as:template<class charT, class traits, class moneyT> void f(basic_ios<charT, traits>& str, moneyT& mon, bool intl) { using Iter = istreambuf_iterator<charT, traits>;using MoneyGet = money_get<charT, Iter>; ios_base::iostate err = ios_base::goodbit;const MoneyGet& mg = use_facet<MoneyGet>(str.getloc()); mg.get(Iter(str.rdbuf()), Iter(), intl, str, err, mon);if (ios_base::goodbit != err) str.setstate(err);}

The expression in >> get_money(mon, intl) has typebasic_istream<charT, traits>& and value in.

template<class moneyT> _unspecified_ put_money(const moneyT& mon, bool intl = false);

Mandates: The type moneyT is either long double or a specialization of the basic_string template ([strings]).

Returns: An object of unspecified type such that ifout is an object of type basic_ostream<charT, traits>then the expression out << put_money(mon, intl) behaves as aformatted output function that callsf(out, mon, intl), where the function f is defined as:template<class charT, class traits, class moneyT> void f(basic_ios<charT, traits>& str, const moneyT& mon, bool intl) { using Iter = ostreambuf_iterator<charT, traits>;using MoneyPut = money_put<charT, Iter>;const MoneyPut& mp = use_facet<MoneyPut>(str.getloc());const Iter end = mp.put(Iter(str.rdbuf()), intl, str, str.fill(), mon);if (end.failed()) str.setstate(ios_base::badbit);}

The expression out << put_money(mon, intl) has typebasic_ostream<charT, traits>& and value out.

template<class charT> _unspecified_ get_time(tm* tmb, const charT* fmt);

Preconditions: The argument tmb is a valid pointer to an object of type tm, and [fmt, fmt + char_traits<charT>​::​length(fmt)) is a valid range.

Returns: An object of unspecified type such that if in is an object of typebasic_istream<charT, traits> then the expression in >> get_time(tmb, fmt) behaves as if it called f(in, tmb, fmt), where the function f is defined as:template<class charT, class traits> void f(basic_ios<charT, traits>& str, tm* tmb, const charT* fmt) { using Iter = istreambuf_iterator<charT, traits>;using TimeGet = time_get<charT, Iter>; ios_base::iostate err = ios_base::goodbit;const TimeGet& tg = use_facet<TimeGet>(str.getloc()); tg.get(Iter(str.rdbuf()), Iter(), str, err, tmb, fmt, fmt + traits::length(fmt));if (err != ios_base::goodbit) str.setstate(err);}

The expression in >> get_time(tmb, fmt) has typebasic_istream<charT, traits>& and value in.

template<class charT> _unspecified_ put_time(const tm* tmb, const charT* fmt);

Preconditions: The argument tmb is a valid pointer to an object of type tm, and [fmt, fmt + char_traits<charT>​::​length(fmt)) is a valid range.

Returns: An object of unspecified type such that if out is an object of type basic_ostream<charT, traits> then the expressionout << put_time(tmb, fmt) behaves as if it called f(out, tmb, fmt), where the function f is defined as:template<class charT, class traits> void f(basic_ios<charT, traits>& str, const tm* tmb, const charT* fmt) { using Iter = ostreambuf_iterator<charT, traits>;using TimePut = time_put<charT, Iter>;const TimePut& tp = use_facet<TimePut>(str.getloc());const Iter end = tp.put(Iter(str.rdbuf()), str, str.fill(), tmb, fmt, fmt + traits::length(fmt));if (end.failed()) str.setstate(ios_base::badbit);}

The expression out << put_time(tmb, fmt) has typebasic_ostream<charT, traits>& and value out.

31.7.9 Quoted manipulators [quoted.manip]

[Note 1:

Quoted manipulators provide string insertion and extraction of quoted strings (for example, XML and CSV formats).

Quoted manipulators are useful in ensuring that the content of a string with embedded spaces remains unchanged if inserted and then extracted via stream I/O.

— _end note_]

template<class charT> _unspecified_ quoted(const charT* s, charT delim = charT('"'), charT escape = charT('\\'));template<class charT, class traits, class Allocator> _unspecified_ quoted(const basic_string<charT, traits, Allocator>& s, charT delim = charT('"'), charT escape = charT('\\'));template<class charT, class traits> _unspecified_ quoted(basic_string_view<charT, traits> s, charT delim = charT('"'), charT escape = charT('\\'));

Returns: An object of unspecified type such that if out is an instance of basic_ostream with member type char_type the same ascharT and with member type traits_type, which in the second and third forms is the same as traits, then the expressionout << quoted(s, delim, escape)behaves as a formatted output functionof out.

This forms a character sequence seq, initially consisting of the following elements:

Let x be the number of elements initially in seq.

Then padding is determined for seq as described in [ostream.formatted.reqmts], seq is inserted as if by callingout.rdbuf()->sputn(seq, n), where n is the larger ofout.width() and x, and out.width(0) is called.

The expression out << quoted(s, delim, escape) has typebasic_ostream<charT, traits>& and value out.

template<class charT, class traits, class Allocator> _unspecified_ quoted(basic_string<charT, traits, Allocator>& s, charT delim = charT('"'), charT escape = charT('\\'));

Returns: An object of unspecified type such that:

31.7.10 Print functions [print.fun]

template<class... Args> void print(format_string<Args...> fmt, Args&&... args);

Effects: Equivalent to:print(stdout, fmt, std::forward<Args>(args)...);

template<class... Args> void print(FILE* stream, format_string<Args...> fmt, Args&&... args);

Effects: Let locksafe be(enable_nonlocking_formatter_optimization<remove_cvref_t<Args>> && ...).

If the ordinary literal encoding ([lex.charset]) is UTF-8, equivalent to:locksafe? vprint_unicode(stream, fmt.str, make_format_args(args...)) : vprint_unicode_buffered(stream, fmt.str, make_format_args(args...));

Otherwise, equivalent to:locksafe? vprint_nonunicode(stream, fmt.str, make_format_args(args...)) : vprint_nonunicode_buffered(stream, fmt.str, make_format_args(args...));

template<class... Args> void println(format_string<Args...> fmt, Args&&... args);

Effects: Equivalent to:println(stdout, fmt, std::forward<Args>(args)...);

Effects: Equivalent to:println(stdout);

template<class... Args> void println(FILE* stream, format_string<Args...> fmt, Args&&... args);

Effects: Equivalent to:print(stream, runtime_format(string(fmt.get()) + '\n'), std::forward<Args>(args)...);

void println(FILE* stream);

Effects: Equivalent to:print(stream, "\n");

void vprint_unicode(string_view fmt, format_args args);

Effects: Equivalent to:vprint_unicode(stdout, fmt, args);

void vprint_unicode_buffered(FILE* stream, string_view fmt, format_args args);

Effects: Equivalent to:string out = vformat(fmt, args); vprint_unicode(stream, "{}", make_format_args(out));

void vprint_unicode(FILE* stream, string_view fmt, format_args args);

Preconditions: stream is a valid pointer to an output C stream.

Effects: Locks stream.

Let out denote the character representation of formatting arguments provided by argsformatted according to specifications given in fmt.

Unconditionally unlocks stream on function exit.

See also: ISO/IEC 9899:2018, 7.21.2.

[Note 1:

On Windows the native Unicode API is WriteConsoleW andstream referring to a terminal means thatGetConsoleMode(_get_osfhandle(_fileno(stream)), ...)returns nonzero.

— _end note_]

system_error if writing to the terminal or stream fails.

May throw bad_alloc.

Recommended practice: If invoking the native Unicode API requires transcoding, implementations should substitute invalid code units with U+fffd replacement character per the Unicode Standard, Chapter 3.9 U+fffd Substitution in Conversion.

void vprint_nonunicode(string_view fmt, format_args args);

Effects: Equivalent to:vprint_nonunicode(stdout, fmt, args);

void vprint_nonunicode_buffered(FILE* stream, string_view fmt, format_args args);

Effects: Equivalent to:string out = vformat(fmt, args); vprint_nonunicode("{}", make_format_args(out));

void vprint_nonunicode(FILE* stream, string_view fmt, format_args args);

Preconditions: stream is a valid pointer to an output C stream.

Effects: While holding the lock on stream, writes the character representation of formatting arguments provided by argsformatted according to specifications given in fmt to stream.

system_error if writing to stream fails.

May throw bad_alloc.