public member function
<iterator>

std::istream_iterator::operator*

reference operator*() const;
Dereference iterator
Returns a reference to the element pointed by the iterator.

Internally, the function returns the value the object stores as its current element.

If the iterator has just been constructed from an input stream, and the implementation of that operation did not extract a value form the stream on construction, it is now extracted.

If the iterator is an end-of-stream iterator it shall not be dereferenced.

Parameters

none

Return value

A constant reference to the element pointed by the iterator.
Member type reference is an alias of const value_type&, where value_type is the type of the elements extracted by the operator (the first class template parameter).

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;
}

Data races

The object is accessed (certain library implementations may also modify it).
The reference returned can be used to access elements.

Exception safety

Strong guarantee: if an exception is thrown, there are no changes in the visible state of the iterator.

See also