[ Web Proxy ]
URL:
Viewing: https://ru.cppreference.com/cpp/io/basic_ostream/~basic_ostream [Back]  [Original]

std::basic_ostream::~basic_ostream cppreference.com
cppreference.com

std::basic_ostream::~basic_ostream

cppreference.com

<metanoindex/>

<tbody> </tbody>
virtual ~basic_ostream();
basic_ostream . streambuffer (rdbuf()): , std::basic_ofstream std::basic_ostringstream streambuffers.
:
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 streambuffers.
Google.
. .

#include <sstream>
#include <iostream>
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';
}

:

42 is the answer.

Web Proxy Viewer  |  New URL  |  Original Page