std::strstreambuf::underflow
protected: virtual int_type underflow(); |
Читает следующий символ из области получения буфера.
Если в последовательности ввода доступна позиция для чтения (gptr() < egptr()), возвращает (unsigned char)(*gptr()).
В противном случае, если pptr() не равно null и 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>) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/io/strstreambuf/underflow