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>(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 via string out = vformat(os.getloc(), fmt, args);
  • If the function is vprint_unicode and os 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.

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant