std::print

Header: <print>

Format args according to the format string fmt, and print the result to an output stream.

# Declarations

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

(since C++23)

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

(since C++23)

# Parameters

# Notes

Feature-test macro Value Std Feature __cpp_lib_print 202207L (C++23) Formatted output 202403L (C++26)(DR23) Unbuffered formatted output 202406L (C++26)(DR23) Enabling unbuffered formatted output for more formattable types __cpp_lib_format 202207L (C++23) Exposing std::basic_format_string

# Example

#include <cstdio>
#include <filesystem>
#include <print>
 
int main()
{
    std::print("{0} {2}{1}!\n", "Hello", 23, "C++");  // overload (1)
 
    const auto tmp {std::filesystem::temp_directory_path() / "test.txt"};
 
    if (std::FILE* stream{std::fopen(tmp.c_str(), "w")})
    {
        std::print(stream, "File: {}", tmp.string()); // overload (2)
        std::fclose(stream);
    }
}

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
P3107R5C++23only buffered printing operations can be performedcan perform unbuffered printing operations
P3235R3C++23the names of the functions addedby P3107R5 were misleadingchanged the function names

# See also