3.5 KiB
[ostream.formatted.print]
31 Input/output library [input.output]
31.7 Formatting and manipulators [iostream.format]
31.7.6 Output streams [output.streams]
31.7.6.3 Formatted output functions [ostream.formatted]
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)...));
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:
failure to generate output is reported as specified below, and
any exception thrown by the call to vformat is propagated without regard to the value of os.exceptions() and without turning on ios_base::badbit in the error state of os.
After constructing a sentry object, the function initializes a variable with automatic storage duration viastring out = vformat(os.getloc(), fmt, args);
-
If the function is vprint_unicode andos is a stream that refers to a terminal that is capable of displaying Unicode only via a native Unicode API, which is determined in an implementation-defined manner, flushes os and then writes out to the terminal using the native Unicode API; if out contains invalid code units,the behavior is undefined. Then establishes an observable checkpoint ([intro.abstract]).
-
Otherwise inserts the character sequence [out.begin(), out.end()) into os.
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.