std::basic_...sic_istream(3)

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

πŸ’… std::basic_istream::~basic_istream πŸ’…

okay so bestie, this page lives in the C++ Standard Libary manual, and the page itself is std::basic_...sic_istream(3) β€” we’re here for std::basic_istream::~basic_istream. It’s giving destructor era and we’re obsessed ✨


🌸 NAME 🌸

  • std::basic_istream::~basic_istream β€” std::basic_istream::~basic_istream

🌈 Synopsis 🌈

virtual ~basic_istream();

This is the destructor, and it destructs the input stream. slay πŸ’…

πŸ¦‹ Notes πŸ¦‹

Real talk: this destructor does not perform any operation on the underlying streambuffer (rdbuf()). It is not the one handling that.

The destructors of the derived input streams β€” such as std::basic_ifstream and std::basic_istringstream β€” are the ones responsible for calling the destructors of the streambuffers. periodt 🫢

πŸŽ€ Example πŸŽ€

// Run this code

#include <iostream>
#include <sstream>

void print_stringbuf(std::streambuf* p)
{
    std::istream buf(p); // buf shares the buffer with s1
    int n;
    buf >> n;
    std::cout << n;
} // calls the destructor of buf. p remains unaffected

int main()
{
    std::istringstream s1("10 20");
    print_stringbuf(s1.rdbuf());
    int n;
    s1 >> n;
    std::cout << ',' << n << '\n';
}

✨ Output ✨

10,20

xoxo, your local Unix bestie πŸ’– β€” source: cppreference.com, version date: 2024.06.10, page: std::basic_...sic_istream(3) 🌟

πŸ“¦ where this page comes from