std::strstreambuf:: underflow
|
protected
:
virtual int_type underflow ( ) ; |
(obsoleto en C++98)
(eliminado en C++26) |
|
Lee el siguiente carácter del área de obtención del búfer.
Si la secuencia de entrada tiene una posición de lectura disponible ( gptr ( ) < egptr ( ) ), devuelve ( unsigned char ) ( * gptr ( ) ) .
De lo contrario, si pptr() no es nulo y pptr ( ) > egptr ( ) (existe un área de escritura y está ubicada después del área de lectura), extiende el final del área de lectura para incluir los caracteres recientemente escritos en el área de escritura incrementando egptr() a algún valor entre gptr ( ) y pptr() , y luego retorna ( unsigned char ) ( * gptr ( ) ) .
De lo contrario, retorna EOF para indicar fallo.
Contenidos |
Parámetros
(ninguno)
Valor de retorno
El siguiente carácter en el área de obtención, ( unsigned char ) ( * gptr ( ) ) en caso de éxito, EOF en caso de fallo.
Ejemplo
#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"; else std::cout << "underflow() returns '" << char(ch) << "'\n"; return ch; } }; int main() { mybuf sbuf; // read-write dynamic strstreambuf std::iostream stream(&sbuf); int n; stream >> n; stream.clear(); stream << "123"; stream >> n; std::cout << n << '\n'; }
Salida posible:
Before underflow(): size of the get area is 0 size of the put area is 0 After underflow(): size of the get area is 0 size of the put area is 0 underflow() returns EOF Before overflow(): size of the get area is 0 size of the put area is 0 After overflow(): size of the get area is 0 size of the put area is 32 Before underflow(): size of the get area is 0 size of the put area is 32 After underflow(): size of the get area is 3 size of the put area is 32 underflow() returns '1' Before underflow(): size of the get area is 3 size of the put area is 32 After underflow(): size of the get area is 3 size of the put area is 32 underflow() returns EOF 123
Véase también
|
[virtual]
|
lee caracteres de la secuencia de entrada asociada al área de obtención
(función miembro protegida virtual de
std::basic_streambuf<CharT,Traits>
)
|
|
[virtual]
|
retorna el siguiente carácter disponible en la secuencia de entrada
(función miembro protegida virtual de
std::basic_stringbuf<CharT,Traits,Allocator>
)
|
|
[virtual]
|
lee del archivo asociado
(función miembro protegida virtual de
std::basic_filebuf<CharT,Traits>
)
|
|
lee un carácter de la secuencia de entrada sin avanzar la secuencia
(función miembro pública de
std::basic_streambuf<CharT,Traits>
)
|
|
|
extrae caracteres
(función miembro pública de
std::basic_istream<CharT,Traits>
)
|