Scroll to navigation

std::formatter(3) C++ Standard Libary std::formatter(3)

NAME

std::formatter - std::formatter

Synopsis

Defined in header <thread> template< class CharT > (since C++23) struct formatter<std::thread::id, CharT>;

The template specialization of std::formatter for the std::thread::id class allows users to convert a thread identifier to its textual representation using formatting functions.


Format specification

The syntax of format specifications is:

fill-and-align (optional) width (optional)

fill-and-align and width have the same meaning as in standard format specification. The default alignment is >.

The formatted output matches the output of operator<<, adjusted as appropriate for the format specifiers.

Notes


Feature-test macro Value Std Feature __cpp_lib_formatters 202302L (C++23) Formatting std::thread::id and std::stacktrace

Example

// Run this code

#include <format> #include <iostream> #include <thread>

int main() {
std::thread::id this_id = std::this_thread::get_id();
std::thread::id null_id;


std::cout << std::format("current thread id: {}\n", this_id);
std::cout << std::format("{:=^10}\n", null_id); }

Possible output:

current thread id: 140046396632256 ====0=====

See also

formatter defines formatting rules for a given type (C++20) (class template)

2026.11.10 http://cppreference.com