다음을 통해 공유


istream_iterator::istream_iterator

Constructs either an end-of-stream iterator as the default istream_iterator or a istream_iterator initialized to the iterator's stream type from which it reads.

istream_iterator( ); 
istream_iterator( 
   istream_type& _Istr 
);

매개 변수

  • _Istr
    The input stream to be read use to initialize the istream_iterator.

설명

The First constructor initializes the input stream pointer with a null pointer and creates an end-of-stream iterator. The second constructor initializes the input stream pointer with &_Istr, then attempts to extract and store an object of type Type.

The end-of-stream iterator can be use to test whether an istream_iterator has reached the end of a stream.

예제

// 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 a

FakePre-610c6ea83fe84b7ca3a53aad6da83a3f-a44d1dc63cd84b9c9459eabb972f5548

요구 사항

헤더: <iterator>

네임스페이스: std

참고 항목

참조

istream_iterator 클래스

표준 템플릿 라이브러리