std::basic_stringbuf<CharT,Traits,Allocator>::overflow (3) - Linux Manuals
std::basic_stringbuf<CharT,Traits,Allocator>::overflow: std::basic_stringbuf<CharT,Traits,Allocator>::overflow
NAME
std::basic_stringbuf<CharT,Traits,Allocator>::overflow - std::basic_stringbuf<CharT,Traits,Allocator>::overflow
Synopsis
protected:
virtual int_type overflow ( int_type c = Traits::eof() );
Appends the character c to the output character sequence.
If c is the end-of-file indicator (traits::eq_int_type(c,traits::eof()) == true), then there is no character to append. The function does nothing and returns an unspecified value other than traits::eof().
Otherwise, if the output sequence has a write position available or this function can successfully make a write position available, then calls sputc(c) and returns c.
This function can make a write position available if the stringbuf is open for output (mode & ios_base::out) != 0): in this case, it reallocates (or initially allocates) the buffer big enough to hold the entire current buffer plus at least one more character. If the stringbuf is also open for input ((mode & ios_base::in) != 0), then overflow also increases the size of the get area by moving egptr() to point just past the new write position.
Parameters
c - the character to store in the put area
Return value
Traits::eof() to indicate failure, c if the character c was successfully appended, or some value other than Traits::eof() if called with Traits::eof() as the argument.
Notes
This function is different from a typical overflow() which moves the contents of the buffer to the associated character sequence because for a std::basic_stringbuf, the buffer and the associated sequence are one and the same.
Example
In the implementation used to execute this example, overflow() over-allocates the put area to 512 bytes: a call to str() would only return the four initialized bytes, but the next 508 calls to sputc() would not require new calls to overflow()
// Run this code
Possible output: