Skip to content

std::print (C++23)

TL;DR

Output formatted strings directly to stdout—a combination of printf + iostream + type safety, the new way to write Hello World in C++23.

cpp
#include <print>

Core API Cheat Sheet

OperationSignatureDescription
Output to stdoutstd::print(fmt, args...);Format and output to standard output
Output with newlinestd::println(fmt, args...);Automatically append a newline character
Empty linestd::println();Output only a newline character
Output to filestd::print(file, fmt, args...);Output to a specified C file stream
Output to file with newlinestd::println(file, fmt, args...);Newline version
Output to streamstd::print(stream, fmt, args...);Output to a C++ stream

Minimal Example

cpp
#include <print>

int main() {
    // Basic replacement
    std::print("Hello, {}!\n", "World");

    // Automatic newline
    std::println("The answer is {}", 42);

    // User-defined types (if formatter is specialized)
    // std::println("Point: {}", Point{10, 20});
}

Embedded Applicability: Low

  • Relies on the OS and filesystem abstraction layer; bare-metal environments typically lack standard output.
  • Suitable for logging in embedded Linux host tools or test frameworks.
  • The formatting engine incurs significant Flash overhead; it is not recommended for resource-constrained devices.
  • Use fmt library's fmt::print as a fallback option starting from C++11.

Compiler Support

GCCClangMSVC
141819.34

See Also


Part of the content references cppreference.com, licensed under CC-BY-SA 4.0

v0.7.0-9-g940ec1b · 940ec1b · 2026-07-05