Namespaces
Variants
Actions

std::basic_streambuf<CharT,Traits>::overflow

From cppreference.com
< cpp‎ | io‎ | basic streambuf
 
 
 
 
protected:
virtual int_type overflow( int_type ch = Traits::eof() );

The intent of this function is to transmit characters from the put area of the stream buffer to the associated character sequence.

Formally, this function ensures that there is space at the put area for at least one character. The base class version always fails, and a possibly-succeeding implementation can only be provided in derived classes (see implementation requirements). The standard library provides std::strstreambuf::overflow(), (until C++26)std::basic_stringbuf::overflow() and std::basic_filebuf::overflow().

Contents

[edit] Parameters

ch - the character to store in the put area

[edit] Return value

Traits::eof()

[edit] Implementation requirements

Every overriding definition of this virtual function must obey the following constraints, otherwise the behavior is undefined:

  • The effect of the function is to consume some initial subsequence of the characters of the pending sequence . The pending sequence is defined as the concatenation of the following sequences:
    • The put area (formally, empty sequence if pbase() is null, otherwise pptr() - pbase() characters beginning at pbase()).
    • The character ch or nothing if ch is EOF (formally, if Traits::eq_int_type(ch, Traits::eof()) returns true).
  • After consumption, the put area pointers are updated to hold the remaining characters, if any. Formally, let r be the number of characters in the pending sequence not consumed:
    • If r is non-zero, then pbase() and pptr() are set so that all following conditions are satisfied:
      • pptr() - pbase() is r.
      • The r characters starting at pbase() are the associated output stream.
    • If r is zero (all characters of the pending sequence have been consumed), then either pbase() is set to a null value, or pbase() and pptr() are both set to the same non-null value.
  • The function may fail if either appending some character to the associated output stream fails or if it is unable to establish pbase() and pptr() according to the above rules.
  • If the function succeeds, returns some value other than Traits::eof(). Typically, ch is returned to indicate success, except when Traits::eq_int_type(ch, Traits::eof()) returns true, in which case Traits::not_eof(ch) is returned.
  • If the function fails, returns Traits::eof() or throws an exception.

[