std::operator<<(std::basic_stacktrace) - cppreference.com
来自cppreference.com
template< class Allocator > std::ostream& operator<<( std::ostream& os, const std::basic_stacktrace<Allocator>& st ); |
(C++23 起) | |
插入 st 的描述到输出流 os 中。等价于 return os << std::to_string(st);。
参数
| os | - | 输出流 |
| st | - | 要插入其描述的 basic_stacktrace
|
返回值
os。
异常
可能会抛出由实现定义的异常。
示例
#include <stacktrace> #include <iostream> int main() { std::cout << "主函数中获得的栈踪迹:\n"; std::cout << std::stacktrace::current() << '\n'; []{ std::cout << "嵌套 lambda 中获得的栈踪迹:\n"; std::cout << std::stacktrace::current() << '\n'; }(); }
可能的输出:
主函数中获得的栈踪迹: 0# 0x0000000000402E7B in ./prog.exe 1# __libc_start_main in /lib/x86_64-linux-gnu/libc.so.6 2# 0x0000000000402CD9 in ./prog.exe 嵌套 lambda 中获得的栈踪迹: 0# 0x0000000000402DDA in ./prog.exe 1# 0x0000000000402EB2 in ./prog.exe 2# __libc_start_main in /lib/x86_64-linux-gnu/libc.so.6 3# 0x0000000000402CD9 in ./prog.exe