std::basic_...c_streambuf(3)

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

πŸ’– NAME πŸ’–

okay so this is page std::basic_...c_streambuf(3) from the C++ Standard Libary manual, and the star of the show is std::basic_streambuf::~basic_streambuf β€” also literally std::basic_streambuf::~basic_streambuf, yes bestie, it’s listed twice and we’re keeping both. πŸ’…


✨ Synopsis ✨

virtual ~basic_streambuf();

This destructor has no effect: the members of this basic_streambuf β€” the pointers and the locale β€” are destructed in accordance with the usual object destruction sequence after this destructor returns. But because it’s declared public virtual, it allows the objects that are derived from std::basic_streambuf to be deleted through a pointer to base class. That’s the whole point, no cap. 🫢


πŸŽ€ Parameters πŸŽ€

  • (none) β€” nothing to pass in, periodt. πŸ’–

🧚 Example 🧚

Run this code, bestie:

#include <fstream>
#include <iostream>

int main()
{
    std::filebuf* fbp = new std::filebuf;
    fbp->open("test.txt", std::ios_base::out);
    fbp->sputn("Hello\n", 6);

    std::streambuf* sbp = fbp;
    delete sbp; // the file is closed, output flushed and written

    std::ifstream f("test.txt");
    std::cout << f.rdbuf(); // proof
}

🌈 Output 🌈

Hello

πŸ’€ Defect reports πŸ’€

The following behavior-changing defect reports were applied retroactively to previously published C++ standards. Lowkey iconic paperwork, ngl. πŸ¦‹

  • DR: LWG 54
    • Applied to: C++98
    • Behavior as published: the effect of the destructor was not specified
    • Correct behavior: specified as no effect

πŸ‘€ See also πŸ‘€

  • constructor β€” constructs a basic_streambuf object (protected member function) ✨

later bestie 🫢 β€” source/version/date check: http://cppreference.com, 2024.06.10, page std::basic_...c_streambuf(3) πŸ’œ

πŸ“¦ where this page comes from