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(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:
  • 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 an automatic variable via string out = vformat(os.getloc(), fmt, args);
If the function is vprint_unicode and os is a stream that refers to a terminal capable of displaying Unicode which is determined in an implementation-defined manner, writes out to the terminal using the native Unicode API; if out contains invalid code units, the behavior is undefined and implementations are encouraged to diagnose it.
If the native Unicode API is used, the function flushes os before writing out.
Otherwise (if os is not such a stream or the function is vprint_nonunicode), 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.