Skip to content

std::print (C++23)

In a Nutshell

Directly outputs formatted strings to stdout -- the fusion of std::format and std::cout, the new C++23 way to write Hello World.

#include <print>

Core API Quick Reference

OperationSignatureDescription
Output to stdoutvoid print(format_string, args...)Format and output to standard output
Output with newlinevoid println(format_string, args...)Automatically appends a newline
Blank linevoid println()Outputs only a newline character
Output to filevoid print(FILE* f, format_string, args...)Output to a specified C file stream
Output to file with newlinevoid println(FILE* f, format_string, args...)Newline version
Output to streamvoid vprint_unicode(std::ostream&, ...)Output to a C++ stream

Minimal Example

cpp
// Standard: C++23
#include <print>

int main() {
    std::print("Hello, {}!\n", "world");
    std::println("value = {}", 42);
    std::println("{:>10.2f}", 3.14159); //       3.14
    std::println();                      // blank line
}

Embedded Applicability: Low

  • Depends on stdout and filesystem abstraction layers; bare-metal environments typically have no standard output
  • Suitable for embedded Linux host-side tools and test framework log output
  • The formatting engine has significant Flash overhead; not recommended for extremely resource-constrained devices
  • The {fmt} library's fmt::print can serve as a fallback for C++11 and later

Compiler Support

GCCClangMSVC
141819.34

See Also


Some content adapted from cppreference.com under CC-BY-SA 4.0 license

Built with VitePress