| I/O manipulators | ||||
| Print functions(C++23) | ||||
| C-style I/O | ||||
| Buffers | ||||
(C++23) | ||||
(C++98/26*) | ||||
(C++20) | ||||
| Streams | ||||
| Abstractions | ||||
| File I/O | ||||
| String I/O | ||||
| Array I/O | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
(C++98/26*) | ||||
(C++98/26*) | ||||
(C++98/26*) | ||||
| Synchronized Output | ||||
(C++20) | ||||
| Types | ||||
| Error category interface | ||||
(C++11) | ||||
(C++11) |
| Public member functions | ||||
| Protected member functions | ||||
strstreambuf::underflow | ||||
protected: virtual int_type underflow(); | (deprecated in C++98) (removed in C++26) | |
Reads the next character from the get area of the buffer.
If the input sequence has a read position available (gptr()< egptr(), returns(unsignedchar)(*gptr()).
Otherwise, ifpptr() is not null andpptr()> egptr() (there is a put area and it is located after the get area), extends the end of the get area to include the characters that were recently written into the put area by incrementingegptr() to some value betweengptr() andpptr(), and then returns(unsignedchar)(*gptr()).
Otherwise, returnsEOF to indicate failure.
Contents |
(none)
The next character in the get area,(unsignedchar)(*gptr()) on success,EOF on failure.
#include <iostream>#include <strstream> struct mybuf:std::strstreambuf{ int_type overflow(int_type c){std::cout<<"Before overflow(): size of the get area is "<< egptr()-eback()<<" size of the put area is "<< epptr()-pbase()<<'\n'; int_type rc= std::strstreambuf::overflow(c);std::cout<<"After overflow(): size of the get area is "<< egptr()-eback()<<" size of the put area is "<< epptr()-pbase()<<'\n';return rc;} int_type underflow(){std::cout<<"Before underflow(): size of the get area is "<< egptr()-eback()<<" size of the put area is "<< epptr()-pbase()<<'\n'; int_type ch= std::strstreambuf::underflow();std::cout<<"After underflow(): size of the get area is "<< egptr()-eback()<<" size of the put area is "<< epptr()-pbase()<<'\n';if(ch==EOF)std::cout<<"underflow() returns EOF\n";elsestd::cout<<"underflow() returns '"<<char(ch)<<"'\n";return ch;}}; int main(){ mybuf sbuf;// read-write dynamic strstreambufstd::iostream stream(&sbuf); int n; stream>> n; stream.clear(); stream<<"123"; stream>> n;std::cout<< n<<'\n';}
Possible output:
Before underflow(): size of the get area is 0 size of the put area is 0After underflow(): size of the get area is 0 size of the put area is 0underflow() returns EOFBefore overflow(): size of the get area is 0 size of the put area is 0After overflow(): size of the get area is 0 size of the put area is 32Before underflow(): size of the get area is 0 size of the put area is 32After underflow(): size of the get area is 3 size of the put area is 32underflow() returns '1'Before underflow(): size of the get area is 3 size of the put area is 32After underflow(): size of the get area is 3 size of the put area is 32underflow() returns EOF123
[virtual] | reads characters from the associated input sequence to the get area (virtual protected member function of std::basic_streambuf<CharT,Traits>)[edit] |
[virtual] | returns the next character available in the input sequence (virtual protected member function of std::basic_stringbuf<CharT,Traits,Allocator>)[edit] |
[virtual] | reads from the associated file (virtual protected member function of std::basic_filebuf<CharT,Traits>)[edit] |
| reads one character from the input sequence without advancing the sequence (public member function of std::basic_streambuf<CharT,Traits>)[edit] | |
| extracts characters (public member function of std::basic_istream<CharT,Traits>)[edit] |