std::formatter<std::basic_stacktrace>
從 cppreference.com
< cpp | utility | basic stacktrace
在標頭 <stacktrace> 定義
|
||
template< class Allocator > struct formatter<std::basic_stacktrace<Allocator>>; |
(C++23 起) | |
std::formatter 針對 std::basic_stacktrace<Allocator> 的特化允許用戶使用如 std::format 這樣的格式化函數把棧蹤跡對象轉換為字符串。
不允許使用任何格式說明符。
如同通過把 std::to_string
(s) 複製到輸出來格式化棧蹤跡對象 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 或文件緩衝區 (函數模板) |