std::strstreambuf::underflow
protected: virtual int_type underflow(); | (устарело в C++98) (удалено в C++26) |
Считывает следующий символ из области чтения буфера.
Если во входной последовательности доступна позиция чтения (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
См. также
|
[виртуальная] | считывает символы из связанной входной последовательности в область чтения (виртуальная защищённая функция-член std::basic_streambuf<CharT,Traits>) |
|
[виртуальная] | возвращает следующий доступный символ во входной последовательности (виртуальная защищённая функция-член std::basic_stringbuf<CharT,Traits,Allocator>) |
|
[виртуальная] | считывает данные из связанного файла (виртуальная защищённая функция-член 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/cpp/io/strstreambuf/underflow