C++ std::println() Function (C++23)

Beginner
5 min read
Updated: Nov 2026
3 examples
C++23

Definition

In C++23, std::println() works like std::print() but it adds a new line at the end of the output. You do not have to write \n yourself.

It takes a format string with {} placeholders and the values to put in. It is the easiest way to print a line in modern C++. Include <print> and compile with -std=c++23.

This is a C++23 function. It is not a stream member: it writes text directly to the terminal (or to a FILE*) without using std::cout. Compile with a C++23 setting such as -std=c++23.

Syntax

Use it like print. The new line is added for you. This is a C++23 feature.

C++
#include <print>

std::println("Hello, {}!", "World");
std::println("{} is {} years old", name, age);
std::println(stderr, "error: {}", code);
CallWhat it does
std::println("Hello")Prints Hello and a new line.
std::println("{} + {} = {}", 2, 3, 5)Prints 2 + 3 = 5 and a new line.
std::println(stderr, "oops")Prints a line to the standard error stream.

println is the same as print with a \n at the end. It is not the same as endl, because it does not flush by itself.

Library declarations
C++
template<class... Args>
void println(std::format_string<Args...> fmt, Args&&... args);

template<class... Args>
void println(FILE* stream, std::format_string<Args...> fmt, Args&&... args);

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

Parameters

ParameterDescription
stream / osOptional. A FILE* such as stdout or stderr, or an std::ostream. Without it, the line goes to stdout.
fmtRequired. The format string. Each {} is replaced by the next value.
argsThe values to print. Their number must match the placeholders.

Return Value

Return ValueDescription
Nothingprintln() returns void. A wrong format string is a compile-time error.

C++ Examples

Example 1 — Print a Line of Text

No is needed. Compile with -std=c++23.

C++
#include <print>

int main() {
    std::println("Hello, C++23!");
    std::println("Second line");
    return 0;
}

How It Works

  1. std::println("Hello, C++23!") prints the text and then a new line.
  2. The second call starts on the next line, because the first one ended its line.
  3. With std::print you would have to write \n at the end of each text.

Example 2 — Fill the Placeholders

Strings and numbers go into the placeholders in order.

C++
#include <print>
#include <string>

int main() {
    std::string name = "Mari";
    int age = 25;

    std::println("{} is {} years old", name, age);
    std::println("next year: {}", age + 1);
    return 0;
}

How It Works

  1. The first {} takes name and the second {} takes age. The values are used in the order you write them.
  2. The type of each value decides how it is printed: text as text, numbers as numbers.
  3. The second call prints the result of age + 1. Any expression can be a value.

Example 3 — Print an Empty Line Between Texts

An empty format string gives just a new line.

C++
#include <print>

int main() {
    std::println("first");
    std::println("");
    std::println("third");
    return 0;
}

How It Works

  1. std::println("first") prints first and ends the line.
  2. std::println("") has no text, so only the new line is written. That makes a blank line.
  3. The third call continues below the blank line.

Frequently Asked Questions

A C++23 function that prints formatted text followed by a new line. It needs #include <print>.
println adds a new line at the end. print does not.
Call std::println(""). The version without arguments is not part of C++23.
The visible result is the same. println uses placeholders and does not flush the stream by itself, while endl flushes.
GCC 14 or later, a recent Clang with a matching standard library, and recent Visual Studio versions. Compile with -std=c++23.

Next: right

Align padded output to the right of its field.

right tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful