Namespaces
Variants
Actions

std::strstream::~strstream

From cppreference.com
< cpp‎ | io‎ | strstream
 
C++
 
Input/output library
 
std::strstream
virtual ~strstream();
(deprecated in C++98)
(removed in C++26)

Destroys a std::strstream 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 strstream and freeze(false) was not called after that, this destructor leaks memory.

[edit] Example

#include <iostream>
#include <strstream>
 
int main()
{
    {
        std::ostrstream s; / dynamic buffer 
        s << 1.23 << std::ends;
        std::cout << s.str() << '\n';
        s.freeze(false);
    } / destructor called, buffer deallocated 
 
    {
        std::ostrstream s;
        s << 1.23 << std::ends;
        std::cout << s.str() << '\n';
/      buf.freeze(false);
    } / destructor called, memory leaked
 
    {
        std::istrstream s("1.23"); / constant buffer
        double d;
        s >> d;
        std::cout << d << '\n';
    } / destructor called, nothing to deallocate
}

Output:

1.23
1.23
1.23

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant