##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::ostrstream::~ostrstream

From cppreference.com
< cpp‎ | io‎ | ostrstream

virtual ~ostrstream(); |  |

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 <strstream>
    #include <iostream>

    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

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/io/ostrstream/%7Eostrstream&oldid=69157"