名前空間
変種
操作

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

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

入力領域にさらにデータを読み込みます。

基底クラスの std::basic_streambuf::underflow のように動作します。 ただし、紐付けられている文字シーケンス (ファイル) から get 領域にデータを読み込むために、まずファイルから (必要なだけ確保された) 一時バッファにデータを読み込み、その後、外部 (一般的にはマルチバイト) 表現を get 領域に投入するために使用される内部形式に変換するために、設定されているロケールの std::codecvt::in を使用します。 ロケールの std::codecvt::always_noconvtrue を返した場合、変換はスキップされるかもしれません。

目次

[編集] 引数

(なし)

[編集] 戻り値

成功した場合は 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

[編集] 関連項目

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