Skip to content

std::println

Defined in header <print>
template< class... Args >
void println( std::format_string<Args...> fmt, Args&&... args );
template< class... Args >
void println( std::format_string<Args...> fmt, Args&&... args );
since C++23
(1)
template< class... Args >
void println( std::FILE* stream,
            std::format_string<Args...> fmt, Args&&... args );
template< class... Args >
void println( std::FILE* stream,
            std::format_string<Args...> fmt, Args&&... args );
since C++23
(2)
void println();
void println();
since C++26
(3)
void println( std::FILE* stream );
void println( std::FILE* stream );
since C++26
(4)

Format args according to the format string fmt with appended \n (which means that each output ends with a new-line), and print the result to a stream.

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

  2. Equivalent to performing the following operations:

    • std::print(stream, "{}\n", std::format(fmt, std::forward<Args>(args)...));
      (until C++26)
    • std::print(stream, std::runtime_format(std::string(fmt.get()) + '\n'), std::forward<Args>(args)...)
      (since C++26)
  3. Equivalent to std::println(stdout).

  4. Equivalent to std::print(stream, "\n").

If std::formatter<Ti, char> does not meet the BasicFormatter requirements for any Ti in Args (as required by std::make_format_args), the behavior is undefined.

output file stream to write to

  • an object that represents the format string. The format string consists of
  • ordinary characters (except { and }), which are copied unchanged to the output,
  • escape sequences {{ and }}, which are replaced with { and } respectively in the output, and
  • replacement fields.

Each replacement field has the following format:

|{ arg-id (optional) } |(1)| |{ arg-id (optional) : format-spec } |(2)|

  1. replacement field without a format specification
  2. replacement field with a format specification
    • arg-id - specifies the index of the argument in args whose value is to be used for formatting; if it is omitted, the arguments are used in order.