public member function
<iterator>

std::istream_iterator::istream_iterator

default (1)
istream_iterator();
initialization (2)
istream_iterator (istream_type& s);
copy (3)
istream_iterator (const istream_iterator& x);
default (1)
istream_iterator();      // constexpr if value_type is literal type
initialization (2)
istream_iterator (istream_type& s);
copy (3)
istream_iterator (const istream_iterator& x) = default;
Construct istream iterator
Constructs an istream_iterator object:

(1) default constructor
Constructs an end-of-stream istream iterator.
(2) initalization constructor
Constructs an istream iterator that is associated with stream s (the object does not own or copy the stream, only stores a reference).
The constructor may automatically attempt to extract an element from s, or defer such an operation until it is dereferenced for the first time.
(3) copy constructor
Constructs an istream iterator, with the same istream reference and current value (it does not attempt to extract an additional element on construction).

Parameters

s
A stream object, which is associated to the iterator.
Member type istream_type is the type of such stream (defined as an alias of basic_istream<charT,traits>, where charT and trais are the second and third class template parameters).
x
An iterator of the same istream_iterator type, whose state is copied.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// istream_iterator example
#include <iostream>     // std::cin, std::cout
#include <iterator>     // std::istream_iterator

int main () {
  double value1, value2;
  std::cout << "Please, insert two values: ";

  std::istream_iterator<double> eos;              // end-of-stream iterator
  std::istream_iterator<double> iit (std::cin);   // stdin iterator

  if (iit!=eos) value1=*iit;

  ++iit;
  if (iit!=eos) value2=*iit;

  std::cout << value1 << "*" << value2 << "=" << (value1*value2) << '\n';

  return 0;
}

Possible output:

Please, insert two values: 120 200
120*200=24000


See also