命名空间
变体
操作

std::operator<<(std::basic_stacktrace)

来自 cppreference.cn
 
 
 
 
定义于头文件 <stacktrace>
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 << "The stacktrace obtained in the main function:\n";
    std::cout << std::stacktrace::current() << '\n';
    []{
        std::cout << "The stacktrace obtained in a nested lambda:\n";
        std::cout << std::stacktrace::current() << '\n';
    }();
}

可能的输出

The stacktrace obtained in the main function:
 0# 0x0000000000402E7B in ./prog.exe
 1# __libc_start_main in /lib/x86_64-linux-gnu/libc.so.6
 2# 0x0000000000402CD9 in ./prog.exe
 
The stacktrace obtained in a nested 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

[编辑] 参阅

执行 stacktrace_entry 的流输出
(函数模板) [编辑]