std::ostrst...~ostrstream(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

okay bestie, welcome to the C++ Standard Libary page for std::ostrst...~ostrstream(3) β€” we're talking about the std::ostrstream::~ostrstream destructor, and it's giving legacy-era energy πŸ’…βœ¨

πŸ’– NAME πŸ’–

std::ostrstream::~ostrstream β€” std::ostrstream::~ostrstream

🌸 Synopsis 🌸

virtual ~ostrstream();  (deprecated in C++98)
                        (removed in C++26)

This destructor 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. Cleanup when it happens? Iconic. 🫢

⚠️ Heads up: this is deprecated in C++98 and removed in C++26, so yeah, it's a whole historical artifact, not a main-character modern API.

πŸŽ€ Parameters πŸŽ€

(none) β€” literally zero parameters, bestie. Not a single one. πŸ’€

😭 Notes 😭

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

🚨 That is a real memory leak, not a vibe. Do not ignore the freeze(false), queen.

🧚 Example 🧚

// Run this code β€” go off, bestie:

#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

mwah πŸ’‹ this page came from http://cppreference.com, dated 2024.06.10, and lives under std::ostrst...~ostrstream(3) β€” bye bestie, don't leak memory! 🫢✨

πŸ“¦ where this page comes from