Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C++

std::println — formatted output with a newline

std::println from <print> formats arguments, writes the result, and appends a newline. It uses stdout by default; an overload accepting FILE* lets you select another output stream.

Version: C++23; repository compiler flag, production runtime not attested

Syntax

#include <print>
std::println("format", args...);
std::println(stream, "format", args...);

std::println is a C++23 standard-library function declared in <print>. Calling std::println("format", args...) writes formatted text to stdout and appends \n. It returns void. Unlike std::print, it automatically ends the text with a newline; this does not guarantee that the buffer is flushed on every call.

The {} fields consume successive arguments. A format specification can follow a colon: {:04d} requests a decimal integer in a field at least four characters wide, padded with zeros. In the example, 42 becomes 0042; a larger number is not truncated.

The form std::println(stream, "format", args...) takes a valid FILE* pointing to an output stream as its first argument. Write failures can throw std::system_error, and formatting and allocation can also throw exceptions.

A compiler and standard library supporting <print> are required; a C++23 flag alone does not establish availability. Entry version: C++23; repository compiler flag, production runtime not attested. The supplied sources describe the evolving standard draft, which can include additions later than C++23.

Examples

#include <print>

int main() {
    std::println("{}: {:04d}", "Score", 42);
}

Result

Score: 0042

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources