Can anyone explain what an iterator is??
Printable View
Can anyone explain what an iterator is??
There are also input stream iterators that make filling/displaying containers much easier.
the word iterator is almost synonymous with the word placeholder. That is, an iterator is used to store a position of an element. (either in a container or a stream)
You may be familiar with the way that a pointer can be used as a 'placeholder' for an element in an array; an iterator is really just a neatly packaged abstraction of that concept. (with built in range checking, so its safer too)
>> with built in range checking, so its safer too
The concept of an iterator does not include range checking, and most STL iterators also do not include built-in range checking.
ah ok, my bad. I was under the impression that STL iterators would throw an out of range exception if you went beyond the container limits. then again, perhaps that's not really range checking :)Quote:
Originally Posted by Daved
I think the .at() function with strings does that, out of range checking I mean. Not sure about whether vectors have that ...
Vectors have at(), and it throws.
No iterator I've ever seen throws. They might assert(), but they do not throw.
thanks for the help. I got it.