std::basic_streambuf<CharT,Traits>::overflow (3) - Linux Manuals
std::basic_streambuf<CharT,Traits>::overflow: std::basic_streambuf<CharT,Traits>::overflow
Command to display std::basic_streambuf<CharT,Traits>::overflow
manual in Linux: $ man 3 std::basic_streambuf<CharT,Traits>::overflow
NAME
std::basic_streambuf<CharT,Traits>::overflow - std::basic_streambuf<CharT,Traits>::overflow
Synopsis
virtual int_type overflow( int_type ch = Traits::eof() );
Ensures that there is space at the put_area for at least one character by saving some initial subsequence of characters starting at pbase() to the output sequence and updating the pointers to the put area (if needed). If ch is not Traits::eof() (i.e. Traits::eq_int_type(ch, Traits::eof()) != true), it is either put to the put area or directly saved to the output sequence.
The function may update pptr, epptr and pbase pointers to define the location to write more data. On failure, the function ensures that either pptr() == nullptr or pptr() == epptr.
The base class version of the function does nothing. The derived classes may override this function to allow updates to the put area in the case of exhaustion.
Parameters
ch - the character to store in the put area
Return value
Returns unspecified value not equal to Traits::eof() on success, Traits::eof() on failure.
The base class version of the function returns Traits::eof().
Note
The sputc() and sputn() call this function in case of an overflow (pptr() == nullptr or pptr() >= epptr()).
Example
// Run this code
#include <iostream>
#include <array>
// Buffer for std::ostream implemented by std::array
template<std::size_t SIZE, class CharT = char>
class ArrayedStreamBuffer : public std::basic_streambuf<CharT> {
public:
using Base = std::basic_streambuf<CharT>;
using char_type = typename Base::char_type;
using int_type = typename Base::int_type;
ArrayedStreamBuffer() : buffer_{} // value-initialize buffer_ to all zeroes
{
Base::setp(buffer_.begin(), buffer_.end()); // set std::basic_streambuf
// put area pointers to work with 'buffer_'
}
int_type overflow(int_type ch)
{
std::cout << "overflow\n";
return Base::overflow(ch);
}
void print_buffer()
{
for (const auto& i: buffer_) {
if (i == 0) {
std::cout << "NULL";
} else {
std::cout << i;
}
std::cout << " ";
}
std::cout << "\n";
}
private:
std::array<char_type, SIZE> buffer_;
};
int main()
{
ArrayedStreamBuffer<10> streambuf;
std::ostream stream(&streambuf);
stream << "hello";
streambuf.print_buffer();
if (stream.good()) {
std::cout << "stream is good\n";
}
stream << "world";
streambuf.print_buffer();
if (stream.good()) {
std::cout << "stream is good\n";
}
stream << "!";
streambuf.print_buffer();
if (!stream.good()) {
std::cout << "stream is not good\n";
}
}
Output:
h e l l o NULL NULL NULL NULL NULL
stream is good
h e l l o w o r l d
stream is good
overflow
h e l l o w o r l d
stream is not good
See also
uflow reads characters from the associated input sequence to the get area and advances the next pointer
(virtual protected member function)
[virtual]
underflow reads characters from the associated input sequence to the get area
(virtual protected member function)
[virtual]
overflow writes characters to the associated file from the put area
(virtual protected member function of std::basic_filebuf<CharT,Traits>)
[virtual]
overflow appends a character to the output sequence
(virtual protected member function of std::basic_stringbuf<CharT,Traits,Allocator>)
[virtual]
overflow appends a character to the output sequence, may reallocate or initially allocate the buffer if dynamic and not frozen
(virtual protected member function of std::strstreambuf)
[virtual]
Pages related to std::basic_streambuf<CharT,Traits>::overflow
- std::basic_streambuf<CharT,Traits>::operator= (3) - std::basic_streambuf<CharT,Traits>::operator=
- std::basic_streambuf<CharT,Traits>::basic_streambuf (3) - std::basic_streambuf<CharT,Traits>::basic_streambuf
- std::basic_streambuf<CharT,Traits>::eback,gptr,egptr (3) - std::basic_streambuf<CharT,Traits>::eback,gptr,egptr
- std::basic_streambuf<CharT,Traits>::gbump (3) - std::basic_streambuf<CharT,Traits>::gbump
- std::basic_streambuf<CharT,Traits>::getloc (3) - std::basic_streambuf<CharT,Traits>::getloc
- std::basic_streambuf<CharT,Traits>::in_avail (3) - std::basic_streambuf<CharT,Traits>::in_avail
- std::basic_streambuf<CharT,Traits>::pbackfail (3) - std::basic_streambuf<CharT,Traits>::pbackfail
- std::basic_streambuf<CharT,Traits>::pbase,std::basic_streambuf<CharT,Traits>::pptr, (3) - std::basic_streambuf<CharT,Traits>::pbase,std::basic_streambuf<CharT,Traits>::pptr,
- std::basic_streambuf<CharT,Traits>::pbase,std::basic_streambuf<CharT,Traits>::pptr,std::basic_streambuf<CharT,Traits>::epptr (3) - std::basic_streambuf<CharT,Traits>::pbase,std::basic_streambuf<CharT,Traits>::pptr,std::basic_streambuf<CharT,Traits>::epptr
- std::basic_streambuf<CharT,Traits>::pbump (3) - std::basic_streambuf<CharT,Traits>::pbump
- std::basic_streambuf<CharT,Traits>::pubimbue,std::basic_streambuf<CharT,Traits>::imbue (3) - std::basic_streambuf<CharT,Traits>::pubimbue,std::basic_streambuf<CharT,Traits>::imbue
- std::basic_streambuf<CharT,Traits>::pubseekoff, (3) - std::basic_streambuf<CharT,Traits>::pubseekoff,
- std::basic_streambuf<CharT,Traits>::pubseekoff,std::basic_streambuf<CharT,Traits>::seekoff (3) - std::basic_streambuf<CharT,Traits>::pubseekoff,std::basic_streambuf<CharT,Traits>::seekoff
- std::basic_streambuf<CharT,Traits>::pubseekpos, (3) - std::basic_streambuf<CharT,Traits>::pubseekpos,
- std::basic_streambuf<CharT,Traits>::pubseekpos,std::basic_streambuf<CharT,Traits>::seekpos (3) - std::basic_streambuf<CharT,Traits>::pubseekpos,std::basic_streambuf<CharT,Traits>::seekpos
- std::basic_streambuf<CharT,Traits>::pubsetbuf,std::basic_streambuf<CharT,Traits>::setbuf (3) - std::basic_streambuf<CharT,Traits>::pubsetbuf,std::basic_streambuf<CharT,Traits>::setbuf
- std::basic_streambuf<CharT,Traits>::pubsync,std::basic_streambuf<CharT,Traits>::sync (3) - std::basic_streambuf<CharT,Traits>::pubsync,std::basic_streambuf<CharT,Traits>::sync
- std::basic_streambuf<CharT,Traits>::sbumpc (3) - std::basic_streambuf<CharT,Traits>::sbumpc
- std::basic_streambuf<CharT,Traits>::setg (3) - std::basic_streambuf<CharT,Traits>::setg
- std::basic_streambuf<CharT,Traits>::setp (3) - std::basic_streambuf<CharT,Traits>::setp
- std::basic_streambuf<CharT,Traits>::sgetc (3) - std::basic_streambuf<CharT,Traits>::sgetc
- std::basic_streambuf<CharT,Traits>::sgetn,std::basic_streambuf<CharT,Traits>::xsgetn (3) - std::basic_streambuf<CharT,Traits>::sgetn,std::basic_streambuf<CharT,Traits>::xsgetn
- std::basic_streambuf<CharT,Traits>::showmanyc (3) - std::basic_streambuf<CharT,Traits>::showmanyc
- std::basic_streambuf<CharT,Traits>::snextc (3) - std::basic_streambuf<CharT,Traits>::snextc
- std::basic_streambuf<CharT,Traits>::sputbackc (3) - std::basic_streambuf<CharT,Traits>::sputbackc
- std::basic_streambuf<CharT,Traits>::sputc (3) - std::basic_streambuf<CharT,Traits>::sputc
- std::basic_streambuf<CharT,Traits>::sputn,std::basic_streambuf<CharT,Traits>::xsputn (3) - std::basic_streambuf<CharT,Traits>::sputn,std::basic_streambuf<CharT,Traits>::xsputn
- std::basic_streambuf<CharT,Traits>::sungetc (3) - std::basic_streambuf<CharT,Traits>::sungetc
- std::basic_streambuf<CharT,Traits>::swap (3) - std::basic_streambuf<CharT,Traits>::swap
- std::basic_streambuf<CharT,Traits>::uflow (3) - std::basic_streambuf<CharT,Traits>::uflow
- std::basic_streambuf<CharT,Traits>::underflow (3) - std::basic_streambuf<CharT,Traits>::underflow
- std::basic_streambuf<CharT,Traits>::~basic_streambuf (3) - std::basic_streambuf<CharT,Traits>::~basic_streambuf
- std::basic_streambuf (3) - std::basic_streambuf