There is both a tough, formal explanation, and a practical one.
Tough, official explanation
Since it is indicated in C ++.
Practical explanation
A vector is always stored in contiguous memory by definition. An iterator is, more or less, a pointer. Therefore, by comparing the actual base memory addresses, you can determine which pointer is βlessβ or βmoreβ than another pointer.
On the other hand, each item in a list or set can be stored anywhere. Each item is created independently. An iterator for one particular element in the list may refer to a numerically smaller memory cell than another iterator for another element in the same list, but the actual element may be after another element in the actual list. Given the two iterators in the list, you cannot immediately determine which one is closer to the beginning or end of the list. Note that inserting and deleting items in a list does not invalidate existing list iterators, since each item in the list is created independently.
The practical reason you cannot use iterators from operator<< to std::ostream is because, of course, this overload is undefined. Please note that you can always do the following:
cout << &*itr << endl;
This will format the actual memory address of the item. But still this is a dubious use. This is basically pointless.
source share