std::to_string
來自 cppreference.com
< cpp | 工具庫 | basic_stacktrace
定義於標頭檔案 <stacktrace> |
||
template< class Allocator > std::string to_string( const std::basic_stacktrace<Allocator>& st ); |
(C++23 起) | |
返回包含 `st` 描述的字串。
`basic_stacktrace` 的描述通常包含其條目的描述,儘管行數不要求等於 size()
。
目錄 |
[編輯] 引數
st | - | 一個 `basic_stacktrace`,其描述將被返回 |
[編輯] 返回值
一個包含 `st` 描述的字串。
[編輯] 異常
可能丟擲實現定義的異常。
[編輯] 注意
此函式不支援自定義分配器,因為實現通常需要平臺特定的分配、系統呼叫和大量 CPU 密集型工作,而自定義分配器對此函式沒有益處,因為平臺特定操作所需的時間比分配要長一個數量級。
[編輯] 示例
執行此程式碼
#include <stacktrace> #include <string> #include <iostream> int main() { auto trace = std::stacktrace::current(); std::cout << std::to_string(trace) << '\n'; }
可能的輸出
0# 0x0000000000402D97 in ./prog.exe 1# __libc_start_main in /lib/x86_64-linux-gnu/libc.so.6 2# 0x0000000000402CA9 in ./prog.exe
[編輯] 另請參閱
(C++23) |
返回描述 stacktrace_entry 的字串(函式) |