I was reading Stanley Lippman's book C++ Primer to learn more about C++ 11.
In the chapter on Generic Algorithms he mentions that iterators used in the generic algorithms can be classified into 5 types based on the operations they support : input iterators, output iterators, forward iterators, bidirectional iterators and random access iterators.
Quote from his book:
Input iterators can read elements in a sequence. They must provide the following operators - equality (
==), inequality (!=), dereference (*), postfix&prefix increment (++) and the arrow operator (->). Input iterators may be used only sequentially. We are guaranteed that*it++is valid, but incrementing an input iterator may invalidate all other iterators on that stream. As a result there is no guarantee that we can save the state of an input iterator and examine an element through that saved iterator
I have trouble understanding the quote in bold. Why would incrementing an input iterator which is meant only for reading elements invalidate other iterators? Why cant we save the state of an input iterator?