std::strstreambuf:: underflow
|
protected
:
virtual int_type underflow ( ) ; |
(устарело в C++98)
(удалено в C++26) |
|
Считывает следующий символ из области получения буфера.
Если во входной последовательности доступна позиция чтения ( gptr ( ) < egptr ( ) ), возвращает ( unsigned char ) ( * gptr ( ) ) .
В противном случае, если pptr() не равен нулю и pptr ( ) > egptr ( ) (имеется область записи и она расположена после области чтения), расширяет конец области чтения, включая символы, недавно записанные в область записи, путем увеличения egptr() до некоторого значения между gptr ( ) и pptr() , и затем возвращает ( unsigned char ) ( * gptr ( ) ) .
В противном случае возвращает EOF для указания на ошибку.
Содержание |
Параметры
(нет)
Возвращаемое значение
Следующий символ в области получения, ( unsigned char ) ( * gptr ( ) ) при успехе, EOF при неудаче.
Пример
#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'; }
Возможный вывод:
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
Смотрите также
|
[virtual]
|
читает символы из связанной входной последовательности в область получения
(виртуальная защищенная функция-член
std::basic_streambuf<CharT,Traits>
)
|
|
[virtual]
|
возвращает следующий доступный символ во входной последовательности
(виртуальная защищенная функция-член
std::basic_stringbuf<CharT,Traits,Allocator>
)
|
|
[virtual]
|
читает из связанного файла
(виртуальная защищенная функция-член
std::basic_filebuf<CharT,Traits>
)
|
|
читает один символ из входной последовательности без продвижения последовательности
(публичная функция-член
std::basic_streambuf<CharT,Traits>
)
|
|
|
извлекает символы
(публичная функция-член
std::basic_istream<CharT,Traits>
)
|