std::to_string
From cppreference.com
< cpp | utility | stacktrace entry
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Diagnostics library
(until C++20*)
(C++17)(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
Exception handling failures
(C++11)
(until C++17*)
(until C++17*)
(until C++17*)
(until C++17*)
(TM TS)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++23)
(C++23)
(C++26)
(C++26)
(C++26)
std::stacktrace_entry
to_string(std::stacktrace_entry)
Defined in header
<stacktrace>
std::string to_string( const std::stacktrace_entry & f );
(since C++23)
Returns a string with a description of f
.
The standard recommends that the description should provide information about the contained evaluation, including information from f.source_file() and f.source_line().
[edit] Parameters
f
-
a
stacktrace_entry
whose description is to be returned
[edit] Return value
A string with a description of f
.
[edit] Exceptions
May throw implementation-defined exceptions.
[edit] Notes
Custom allocators support for this function is not provided, because the implementations usually require platform specific allocations, system calls and a lot of CPU intensive work, while a custom allocator does not provide benefits for this function as the platform specific operations take an order of magnitude more time than the allocation.
[edit] Example
Run this code
#include <stacktrace> #include <string> #include <iostream> int main() { auto st = std::stacktrace::current(); std::cout << "Description of an empty stacktrace entry:\n" + std::to_string (std::stacktrace_entry {}) << '\n'; if (st.size() > 0) { std::cout << "Description of a non-empty stacktrace entry:\n" + std::to_string (st[0]) << '\n'; } }
Possible output:
Description of an empty stacktrace entry: Description of a non-empty stacktrace entry: 0x0000000000402DE9 in ./prog.exe