# std::basic_ostream<CharT,Traits>::~basic_ostream

> C++ Atlas: `cppatlas.com/w/cpp/io/basic_ostream/~basic_ostream` | Source: https://en.cppreference.com/w/cpp/io/basic_ostream/~basic_ostream | Domain: Input/output

Destroys the basic_ostream object.

## Official Specification Summary (cppreference)

```cpp
virtual ~basic_ostream();
```

Destroys the `basic_ostream` object. This destructor does not perform any operation on the underlying streambuffer (`rdbuf()`): the destructors of the derived output streams such as `std::basic_ofstream` and `std::basic_ostringstream` are responsible for calling the destructors of the stream buffers.

### Example

```cpp
#include <iostream>
#include <sstream>

void add_words(std::streambuf* p)
{
    std::ostream buf(p); // buf shares the buffer with s
    buf << " is the answer";
} // calls the destructor of buf. p remains unaffected

int main()
{
    std::ostringstream s;
    s << 42;
    add_words(s.rdbuf());
    s << ".";
    std::cout << s.str() << '\n';
}
```

Output:

```text
42 is the answer.
```

---
Attribution: content from https://en.cppreference.com/w/cpp/io/basic_ostream/~basic_ostream (cppreference.com), licensed under CC-BY-SA 3.0 and GFDL. Modified: converted to markdown, study notes added. Offline snapshot of 9 February 2025.