std::strstream::~strstream(3)

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

πŸ’– std::strstream::~strstream πŸ’–

✨ NAME ✨

bestie, this is the C++ Standard Libary manual page for std::strstream::~strstream(3) β€” the destructor for a std::strstream object. The NAME vibe is literally std::strstream::~strstream β€” std::strstream::~strstream, no cap. 🫢


🌸 Synopsis 🌸

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

So it's a virtual destructor, and it was deprecated in C++98 and removed in C++26. It 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. πŸ’…

πŸŽ€ Parameters πŸŽ€

  • (none) β€” literally no parameters, not even one, we love a low-effort queen. ✨

πŸ¦‹ Notes πŸ¦‹

⚠️ memory leak alert: if str() was called on a dynamic strstream and freeze(false) was not called after that, this destructor leaks memory. periodt, that's the whole warning.

🌈 Example 🌈

okay so this example has three little blocks: one clean dealloc, one leaky one, and one constant-buffer β€œnothing to deallocate” moment. watch the vibes 😭

       // Run this code

        #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

🫢 source/version check: http://cppreference.com Β· 2024.06.10 Β· page std::strstream::~strstream(3) β€” byeee bestie πŸ’–

πŸ“¦ where this page comes from