Input Iterator (input_iterator)

Definition

A class input_iterator that satisfies the requirements of an input iterator for the value type T, supports the following operations.

Algorithms on input iterators should never attempt to pass through the same iterator twice. They should be single pass algorithms.

Creation

input_iterator it ( iterator it1);

Operations

iterator& it = iterator it1 Assignment.

T * it Returns the value of the iterator.
Precondition: it is dereferenceable.

iterator& ++ it Prefix increment operation.
Precondition: it is dereferenceable.

iterator it ++ Postfix increment operation. The result is the same as that of (void)++it;.
Precondition: it is dereferenceable.

Example

The following code fragment reads numbers of the type double from cin and computes their sum. The STL provides an istream_iterator that fulfills the input iterator requirements. As the iterator is a kind of file pointer it should be clear why only single pass algorithms can be applied on this iterator.

{
    istream_iterator<double> it(cin),
                             end();
    double sum = 0.0;
    while(it != end){
        sum += *it;
        ++it;
    }
    cout << sum << endl;
}