Table of Contents

<streambuf>

<streambuf> provides std::basic_streambuf, the base class for stream buffers. You rarely derive from this unless you're implementing custom input or output streams. Most code just uses the derived classes provided by <fstream>, <sstream>, etc.

It handles buffering, gets/puts, and low-level I/O operations.

Example

This example accesses the underlying buffer of a string stream and checks its available input.

// compile: g++ -std=c++11 -o streambufexample streambufexample.cpp
// run: ./streambufexample
// description: access stream buffer directly
 
#include <streambuf>
#include <iostream>
#include <sstream>
 
int main() {
    std::stringstream ss;
    ss << "hello world";
 
    std::streambuf* buf = ss.rdbuf();
    std::cout << "buffer size hint: " << buf->in_avail() << "\n";
 
    return 0;
}