std::ostrstream::~ostrstream
From cppreference.com
< cpp | io | ostrstream
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)
Input/output library
Print functions (C++23)
Buffers
(C++23)
(C++98/26*)
(C++20)
Streams
Abstractions
File I/O
String I/O
Array I/O
(C++23)
(C++23)
(C++23)
(C++98/26*)
(C++98/26*)
(C++98/26*)
Synchronized Output
(C++20)
Types
Error category interface
(C++11)
(C++11)
std::ostrstream
Member functions
ostrstream::~ostrstream
virtual ~ostrstream();
(deprecated in C++98) (removed in C++26)
Destroys a std::ostrstream object, which also destroys the member std::strstreambuf , which may call the deallocation function if the underlying buffer was dynamically-allocated and not frozen.
[edit] Parameters
(none)
[edit] Notes
If str() was called on a dynamic ostrstream
and freeze(false)
was not called after that, this destructor leaks memory.
[edit] Example
Run this code
#include <iostream> #include <strstream> int main() { { std::ostrstream s; // dynamic buffer s << 1.23; std::cout << s.str() << '\n'; s.freeze(false); } // destructor called, buffer deallocated { std::ostrstream s; s << 1.23; std::cout << s.str() << '\n'; // buf.freeze(false); } // destructor called, memory leaked }
Output:
1.23 1.23