名前空間
変種
操作

std::strstreambuf::underflow

提供: cppreference.com
< cpp‎ | io‎ | strstreambuf
 
 
入出力ライブラリ
入出力マニピュレータ
Cスタイルの入出力
バッファ
(C++98で非推奨)
ストリーム
抽象
ファイル入出力
文字列入出力
配列入出力
(C++98で非推奨)
(C++98で非推奨)
(C++98で非推奨)
同期化出力
エラーカテゴリインタフェース
(C++11)
 
 
protected:
virtual int_type underflow();

バッファの get 領域から次の文字を読み込みます。

入力シーケンスに利用可能な読み込み位置がある (gptr() < egptr()) 場合は、 (unsigned char)(*gptr()) を返します。

そうでなく、 pptr() がヌルでなく、 pptr() > egptr() である (put 領域が存在し、 get 領域の後に位置している) 場合は、 gptr()pptr() の間のいずれかの値に egptr() をインクリメントすることによって put 領域に最近書き込んだ文字を含むように get 領域の終端を拡張し、 (unsigned char)(*gptr()) を返します。

そうでなければ、失敗を示すために EOF を返します。

目次

[編集] 引数

(なし)

[編集] 戻り値

成功した場合は get 領域の次の文字 (unsigned char)(*gptr())、失敗した場合は EOF

[編集]

#include <strstream>
#include <iostream>
 
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

[編集] 関連項目

[仮想]
紐付けられている入力シーケンスから get 領域に文字を読み込みます
(std::basic_streambuf<CharT,Traits>の仮想プロテクテッドメンバ関数) [edit]
[仮想]
入力シーケンスの次の利用可能な文字を返します
(std::basic_stringbuf<CharT,Traits,Allocator>の仮想プロテクテッドメンバ関数) [edit]
[仮想]
紐付けられているファイルから読み込みます
(std::basic_filebuf<CharT,Traits>の仮想プロテクテッドメンバ関数) [edit]
シーケンスを進めずに入力シーケンスから文字をひとつ読み込みます
(std::basic_streambuf<CharT,Traits>のパブリックメンバ関数) [edit]
文字を抽出します
(std::basic_istream<CharT,Traits>のパブリックメンバ関数) [edit]