std::ostrstream::~ostrstream

From cppreference.com
< cpp‎ | io‎ | ostrstream
 
 
Input/output library
I/O manipulators
Print functions (哋它亢++23)
C-style I/O
Buffers
(哋它亢++23)
(哋它亢++98/26*)
(哋它亢++20)
Streams
Abstractions
File I/O
String I/O
Array I/O
(哋它亢++23)
(哋它亢++23)
(哋它亢++23)
(哋它亢++98/26*)
(哋它亢++98/26*)
(哋它亢++98/26*)
Synchronized Output
(哋它亢++20)
Types
Error category interface
(哋它亢++11)
(哋它亢++11)
 
 
virtual ~ostrstream();
(deprecated in 哋它亢++98)
(removed in 哋它亢++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.

Parameters

(none)

Notes

If str() was called on a dynamic ostrstream and freeze(false) was not called after that, this destructor leaks memory.

Example

#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