Namespaces
Variants

std::basic_filebuf<CharT,Traits>:: underflow

From cppreference.net
protected :
virtual int_type underflow ( )

入力エリアにより多くのデータを読み込みます。

基底クラス std :: basic_streambuf :: underflow と同様に動作しますが、関連付けられた文字シーケンス(ファイル)からデータを取得領域に読み込む際に、まずファイルから一時バッファ(必要に応じて十分な大きさで確保)にバイト列を読み込み、次に設定されたロケールの std :: codecvt :: in を使用して、外部表現(通常はマルチバイト)を内部形式に変換し、その結果を用いて取得領域を埋めます。ロケールの std :: codecvt :: always_noconv true を返す場合、変換は省略されます。

目次

パラメータ

(なし)

戻り値

Traits :: to_int_type ( * gptr ( ) ) 成功時(保留中のシーケンスの最初の文字)、または Traits :: eof ( ) 失敗時。

#include <fstream>
#include <iostream>
struct mybuf : std::filebuf
{
    int underflow()
    {
         std::cout << "Before underflow(): size of the get area is "
                   << egptr()-eback() << " with "
                   << egptr()-gptr() << " read positions available\n";
         int rc = std::filebuf::underflow();
         std::cout << "underflow() returns " << rc << ".\nAfter the call, "
                   << "size of the get area is "
                   << egptr()-eback() << " with "
                   << egptr()-gptr() << " read positions available\n";
        return rc;
    }
};
int main()
{
    mybuf buf;
    buf.open("test.txt", std::ios_base::in);
    std::istream stream(&buf);
    while (stream.get()) ;
}

出力例:

Before underflow(): size of the get area is 0 with 0 read positions available
underflow() returns 73.
After the call, size of the get area is 110 with 110 read positions available
Before underflow(): size of the get area is 110 with 0 read positions available
underflow() returns -1.
After the call, size of the get area is 0 with 0 read positions available

関連項目

[virtual]
関連付けられた入力シーケンスから文字を読み取り、取得領域に格納する
( std::basic_streambuf<CharT,Traits> の仮想保護メンバ関数)
[virtual]
入力シーケンスで利用可能な次の文字を返す
( std::basic_stringbuf<CharT,Traits,Allocator> の仮想保護メンバ関数)
[virtual]
次のポインタを進めずに入力シーケンスから文字を読み取る
( std::strstreambuf の仮想保護メンバ関数)
[virtual]
関連付けられたファイルから読み取り、取得領域の次のポインタを進める
(仮想保護メンバ関数)
[virtual]
出力領域から関連付けられたファイルに文字を書き込む
(仮想保護メンバ関数)
シーケンスを進めずに入力シーケンスから1文字読み取る
( std::basic_streambuf<CharT,Traits> の公開メンバ関数)