[ostream.formatted.print]

# 31 Input/output library [[input.output]](./#input.output)

## 31.7 Formatting and manipulators [[iostream.format]](iostream.format#ostream.formatted.print)

### 31.7.6 Output streams [[output.streams]](output.streams#ostream.formatted.print)

#### 31.7.6.3 Formatted output functions [[ostream.formatted]](ostream.formatted#print)

#### 31.7.6.3.5 Print [ostream.formatted.print]

[ð](#lib:print)

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

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L6811)

*Effects*: If the ordinary literal encoding ([[lex.charset]](lex.charset "5.3.1 Character sets")) 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...));

[ð](#lib:println)

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

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L6830)

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

[ð](#lib:println_)

`void println(ostream& os);
`

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L6844)

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

[ð](#lib:vprint_unicode)

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

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L6860)

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

- [(4.1)](#4.1)

failure to generate output is reported as specified below, and

- [(4.2)](#4.2)

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[.](#4.sentence-1)

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

- [(4.3)](#4.3)

  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[.](#4.3.sentence-1)
  Then establishes an observable checkpoint ([[intro.abstract]](intro.abstract "4.1.2 Abstract machine"))[.](#4.3.sentence-2)

- [(4.4)](#4.4)

  Otherwise
inserts the character sequence
[out.begin(), out.end()) into os[.](#4.4.sentence-1)

If writing to the terminal or inserting into os fails,
calls os.setstate(ios_base​::​badbit) (which may throw ios_base​::​failure)[.](#4.sentence-3)

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L6902)

*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[.](#5.sentence-1)
