<streambuf> <iostream>


typedef basic_streambuf<char> streambuf;
Base buffer class for streams

This template is designed as base virtual class for all stream buffer classes that handle narrow characters (of type char).

It is an instantiation of basic_streambuf with the following template parameters:
template parameterdefinitioncomments
charTcharAliased as member char_type
traitschar_traits<char>Aliased as member traits_type

A stream buffer is an object in charge of performing the reading and writing operations of the stream object it is associated with: the stream delegates all such operations to its associated stream buffer object, which is an intermediary between the stream and its controlled input and output sequences.

All stream objects, no matter whether buffered or unbuffered, have an associated stream buffer: Some stream buffer types may then be set to either use an intermediate buffer or not.

Stream buffer objects keep internally, at least:
  • A locale object, used for locale-dependent operations.
  • A set of internal pointers to keep an input buffer: eback, gptr, egptr.
  • A set of internal pointers to keep an output buffer: pbase, pptr, epptr.

Internally, the streambuf class is an elaborated base class designed to provide a uniform public interface for all derived classes: These public functions call virtual protected members that derived classes may override to implement specific behavior. These overridden virtual functions have access to the internals of the streambuf class by means of a set of protected functions (see below).

Member types

member typedefinition

Public member functions

The common functionality for all stream buffers is provided through the following public member functions:

Buffer management and positioning:
Input functions (get):
Output functions (put):

Protected member functions

The public functions do not perform their operations directly on the controlled input and output sequences, but mostly rely on two arrays accessible by a set of internal pointers:

(beginning pointers)
current position
(get/put pointer)
(end pointers)
Input sequenceebackgptregptr
Output sequencepbasepptrepptr

The following protected member functions provide access to these pointers:

Input sequence (get):
Output sequence (put):

Virtual protected member functions

Each streambuf-derived class shall define members that keep the validity of the pointers above with respect to their own type of controlled sequence; Modifying the values of the pointers, reallocating the sequences themselves and perfoming all necessary synchronizations with the associated character sequence.

With this design, the core functionality involving the process of reading and writing directly to the specific associated character sequence and to manage the controlled sequences is provided by means of virtual functions, which are overriden as necessary by derived classes:


Buffer management and positioning:

Input functions (get):

Output functions (put):