次の方法で共有


istream_iterator::istream_iterator

既定 istream_iterator として終端のストリームの反復子または読み取り反復子のストリーム型に初期化される istream_iterator を構築します。

istream_iterator( ); 
istream_iterator( 
   istream_type& _Istr 
);

パラメーター

  • _Istr
    istream_iteratorを初期化する読み取り使用の入力ストリーム。

解説

最初のコンストラクターは null ポインターの入力ストリームにポインターを初期化し、終端のストリームの反復子を作成します。 2 番目のコンストラクターは _Istrの入力ストリームにポインターを &初期化しましたり、型 [種類] オブジェクトを取得し、保存します。

終わりのストリームの反復子は、istream_iterator がストリームの末尾に到達したかどうかをテストして使用する可能性があります。

使用例

// istream_iterator_istream_iterator.cpp
// compile with: /EHsc
#include <iterator>
#include <vector>
#include <algorithm>
#include <iostream>

int main( )
{
   using namespace std;

   // Used in conjunction with copy algorithm
   // to put elements into a vector read from cin
   vector<int> vec ( 4 );
   vector <int>::iterator Iter;

   cout << "Enter 4 integers separated by spaces & then\n"
        << " a character ( try example: '2 4 6 8 a' ): ";
   istream_iterator<int> intvecRead ( cin );

   // Default constructor will test equal to end of stream
   // for delimiting source range of vecor
   copy ( intvecRead , istream_iterator<int>( ) , vec.begin ( ) );
   cin.clear ( );

   cout << "vec = ";
   for ( Iter = vec.begin( ) ; Iter != vec.end( ) ; Iter++ )
      cout << *Iter << " "; cout << endl;
}
  2 4 6 8 aEnter a2

FakePre-f930a391ffcf4e1593c588879ecc8566-2e7a8d5c68f84d75ae57f3927c96bb0a

必要条件

ヘッダー: の <反復子>

名前空間: std

参照

関連項目

istream_iterator クラス

標準テンプレート ライブラリ