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 std::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 std::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.
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.
[edit] NotesThis 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.
In the implementation used to execute this example (e.g. GCC-4.9), 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()
.
Possible output:
read-write stream: stringbuf::overflow('4') called Before: size of get area: 3 size of put area: 3 After : size of get area: 4 size of put area: 512 1234 read-only stream: stringbuf::overflow('1') called Before: size of get area: 3 size of put area: 0 After : size of get area: 3 size of put area: 0 write-only stream: stringbuf::overflow('4') called Before: size of get area: 0 size of put area: 3 After : size of get area: 0 size of put area: 512[edit] Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior LWG 169 C++98 the buffer (re)allocated could only hold one extra character allows more extra characters LWG 432 C++98overflow
moved epptr() to point just past the new
std::stringbuf
is open for input it is not moved [edit] See also writes characters to the associated output sequence from the put area
std::basic_streambuf<CharT,Traits>
) [edit] returns the next character available in the input sequence
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4