std::istreambuf_iterator - cppreference.com
提供: cppreference.com
<tbody> </tbody> <tbody class="t-dcl-rev "> </tbody><tbody> </tbody>
| ヘッダ |
||
|
|
(C++17未満) | |
|
|
(C++17以上) | |
std::istreambuf_iterator は指定された std::basic_streambuf オブジェクトから連続する文字を読み込むシングルパスの入力イテレータです。
デフォルト構築された std::istreambuf_iterator はストリーム終端イテレータと言います。 有効な std::istreambuf_iterator が、ベースとなるストリームの終端に達すると、ストリーム終端イテレータと等しくなります。 それ以降の逆参照やインクリメントは未定義動作を発生させます。
std::istreambuf_iterator はトリビアルなコピーコンストラクタ、 constexpr デフォルトコンストラクタ、トリビアルなデストラクタを持ちます。
メンバ型
| メンバ型 | 定義 |
iterator_category
|
std::input_iterator_tag
|
value_type
|
CharT
|
difference_type
|
Traits::off_type
|
pointer
|
/* unspecified, usually CharT* */
|
reference
|
CharT
|
char_type
|
CharT
|
traits_type
|
Traits
|
int_type
|
typename traits::int_type
|
streambuf_type
|
std::basic_streambuf<CharT, Traits>
|
istream_type
|
std::basic_istream<CharT, Traits>
|
/* proxy */
|
処理系定義のクラス型。 名前 proxy は説明専用です。proxy オブジェクトは char_type の文字と streambuf_type* のポインタを保持します。proxy オブジェクトを operator* で逆参照すると格納されている文字を返します。
|
|
メンバ型 |
(C++17未満) |
メンバ関数
非メンバ関数
例
#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