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