命名空间
变体
操作

std::formatter<std::basic_stacktrace>

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

std::formatter 的模板特化,用于 std::basic_stacktrace<Allocator>,允许用户使用格式化函数(例如 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 或文件流
(函数模板) [编辑]