From the course: C++ Templates and the STL

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Accessing iterators

Accessing iterators

- [Instructor] An iterator is an STL object that can iterate through the elements of a container. An iterator acts a lot like a pointer. It can be incremented and de-referenced as if it were a pointer. Here I have a working copy of iterator.cpp from chapter three of the exercise files. I've defined a vector of ints and I've defined an iterator it1. The iterator class is defined in the scope of the container class. So, it's accessed using the scope resolution operator or the double colons that we've seen elsewhere. It's technically called a scope resolution operator. And the type of iterator is bound to the type of the class. And so in this case we have a vector int iterator. So, this type of iterator will only work with a vector of ints. It won't work with any other class or templated class. Begin and end iterators are generally available from the begin and end member functions. And so in this case, I've taken an iterator for the begin position and an iterator for the end position…

Contents