Namespaces
Variants

std:: formatter <std::basic_stacktrace>

From cppreference.net
定义于头文件 <stacktrace>
template < class Allocator >
struct formatter < std:: basic_stacktrace < Allocator >> ;
(C++23 起)

针对 std::basic_stacktrace<Allocator> std::formatter 模板特化允许用户通过格式化函数(例如 std::format )将堆栈轨迹对象转换为字符串。

不允许使用格式说明符。

栈迹对象 s 的格式化方式如同将 std::to_string ( s ) 复制到输出流。

示例

#include <format>
#include <iostream>
#include <stacktrace>
int main()
{
    auto trace = std::stacktrace::current();
    std::cout << std::format("{}\n", trace);
}

可能的输出:

 0# 0x0000000000402D97 in ./prog.exe
 1# __libc_start_main in /lib/x86_64-linux-gnu/libc.so.6
 2# 0x0000000000402CA9 in ./prog.exe

参见

(C++20)
为给定类型定义格式化规则
(类模板)
(C++23)
使用参数的 格式化 表示输出到 stdout 或文件流
(函数模板)