名前空間
変種
操作

std::istreambuf_iterator

提供: cppreference.com
< cpp‎ | iterator
 
 
イテレータライブラリ
イテレータコンセプト
イテレータプリミティブ
アルゴリズムのコンセプトとユーティリティ
間接呼び出し可能コンセプト
共通アルゴリズム要件
ユーティリティ
イテレータアダプタ
ストリームイテレータ
istreambuf_iterator
イテレータのカスタマイゼーションポイント
イテレータ操作
範囲アクセス
(C++11)(C++14)
(C++11)(C++14)
(C++17)(C++20)
(C++14)(C++14)
(C++14)(C++14)
(C++17)
(C++17)
 
 
ヘッダ <iterator> で定義
template<class CharT, class Traits =std::char_traits<CharT>>

class istreambuf_iterator :publicstd::iterator<std::input_iterator_tag,
                                                  CharT,
                                                  typename Traits::off_type,
                                                  /* unspecified, usually CharT* */,

                                                  CharT >
(C++17未満)
template<class CharT, class Traits =std::char_traits<CharT>>
class istreambuf_iterator;
(C++17以上)

std::istreambuf_iterator は指定された std::basic_streambuf オブジェクトから連続する文字を読み込むシングルパスの入力イテレータです。

デフォルト構築された std::istreambuf_iteratorストリーム終端イテレータと言います。 有効な std::istreambuf_iterator が、ベースとなるストリームの終端に達すると、ストリーム終端イテレータと等しくなります。 それ以降の逆参照やインクリメントは未定義動作を発生させます。

std::istreambuf_iterator はトリビアルなコピーコンストラクタ、 constexpr デフォルトコンストラクタ、トリビアルなデストラクタを持ちます。

目次

[編集]メンバ型

メンバ型 定義
iterator_categorystd::input_iterator_tag
value_typeCharT
difference_typeTraits::off_type
pointer/* unspecified, usually CharT* */
referenceCharT
char_typeCharT
traits_typeTraits
int_typetypename traits::int_type
streambuf_typestd::basic_streambuf<CharT, Traits>
istream_typestd::basic_istream<CharT, Traits>
/* proxy */ 処理系定義のクラス型。 名前 proxy は説明専用です。
proxy オブジェクトは char_type の文字と streambuf_type* のポインタを保持します。
proxy オブジェクトを operator* で逆参照すると格納されている文字を返します。

メンバ型 iterator_categoryvalue_typedifference_typepointer および referencestd::iterator<std::input_iterator_tag, CharT, Traits::off_type, /* unspecified, usually CharT* */, CharT> から継承することによって取得することが要求されます。

(C++17未満)

[編集]メンバ関数

新しい istreambuf_iterator を構築します
(パブリックメンバ関数)[edit]
デストラクタ
(暗黙に宣言)
istreambuf_iterator を破棄します
(パブリックメンバ関数)[edit]
(C++11以上)(C++17未満)
現在の文字のコピーを取得します
CharT がメンバを持つ場合、現在の文字のメンバにアクセスします
(パブリックメンバ関数)[edit]
イテレータを進めます
(パブリックメンバ関数)[edit]
両方の istreambuf_iterator がストリーム終端または両方が有効であるかどうかを調べます
(パブリックメンバ関数)[edit]

[編集]非メンバ関数

(C++20で削除)
2つの istreambuf_iterator を比較します
(関数テンプレート)[edit]

[編集]

#include <vector>#include <sstream>#include <iostream>#include <iterator>   int main(){// 一般的なユースケース: イテレータの組として表された入力ストリーム。std::istringstream in("Hello, world");std::vector<char> v((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());std::cout<<"v has "<< v.size()<<" bytes. "; v.push_back('\0');std::cout<<"it holds \""<<&v[0]<<"\"\n";     // シングルパスの性質のデモンストレーション。std::istringstream s("abc"); std::istreambuf_iterator<char> i1(s), i2(s);std::cout<<"i1 returns "<<*i1 <<'\n'<<"i2 returns "<<*i2 <<'\n';++i1;std::cout<<"after incrementing i1, but not i2\n"<<"i1 returns "<<*i1 <<'\n'<<"i2 returns "<<*i2 <<'\n';++i2;// これは *i2 の値を見かけ上 'a' から 'c' にジャンプさせます。std::cout<<"after incrementing i2, but not i1\n"<<"i1 returns "<<*i1 <<'\n'<<"i2 returns "<<*i2 <<'\n';   }

出力:

v has 12 bytes. it holds "Hello, world" i1 returns a i2 returns a after incrementing i1, but not i2 i1 returns b i2 returns a after incrementing i2, but not i1 i1 returns b i2 returns c

[編集]関連項目

std::basic_streambuf に書き込む出力イテレータ
(クラステンプレート)[edit]
std::basic_istream から読み込む入力イテレータ
(クラステンプレート)[edit]
close