Namespaces
Variants

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

From cppreference.net
Definiert im Header <stacktrace>
template < class Allocator >
std:: ostream & operator << ( std:: ostream & os, const std:: basic_stacktrace < Allocator > & st ) ;
(seit C++23)

Fügt die Beschreibung von st in den Ausgabestream os ein. Entspricht return os << std:: to_string ( st ) ; .

Inhaltsverzeichnis

Parameter

os - ein Ausgabestrom
st - eine basic_stacktrace , deren Beschreibung einzufügen ist

Rückgabewert

os .

Exceptions

Kann implementierungsdefinierte Ausnahmen auslösen.

Beispiel

#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';
    }();
}

Mögliche Ausgabe:

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

Siehe auch

(C++23)
führt Stream-Ausgabe für stacktrace_entry durch
(Funktions-Template)