std::strstreambuf::underflow
From cppreference.com
< cpp | io | strstreambuf
| protected: virtual int_type underflow(); |
(C++98で非推奨) (C++26で削除) |
|
バッファの get エリアから次の文字を読み取ります。
入力シーケンスに読み取り可能な位置がある場合(gptr() < egptr())、(unsigned char)(*gptr()) を返します。
それ以外の場合で、pptr() が null でなく、かつ pptr() > egptr()(put エリアがあり、それが get エリアの後ろにある)の場合、egptr() を gptr() と pptr() の間の値にインクリメントして get エリアの終端を拡張し、その後 (unsigned char)(*gptr()) を返します。
それ以外の場合、失敗を示すために EOF を返します。
目次 |
[編集] パラメータ
(なし)
[編集] 戻り値
get エリアの次の文字。成功時は (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> の仮想 protected メンバ関数) |
| [virtual] |
入力シーケンスで利用可能な次の文字を返す ( std::basic_stringbuf<CharT,Traits,Allocator>の仮想保護メンバー関数) |
| [virtual] |
関連付けられたファイルから読み込みます。 ( std::basic_filebuf<CharT,Traits>の仮想保護メンバー関数) |
| シーケンスを進めずに、入力シーケンスから1文字を読み取る ( std::basic_streambuf<CharT,Traits> の public メンバ関数) | |
| 文字を抽出する ( std::basic_istream<CharT,Traits> の public メンバ関数) |