std::formatter<std::basic_stacktrace>
來自 cppreference.com
< 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 或檔案流 (函式模板) |