std::formatter<std::basic_stacktrace>
来自 cppreference.cn
< cpp | 工具库 | basic_stacktrace
定义于头文件 <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 或文件流 (函数模板) |