Labs ICT
Pro Login

Iterators

C++ Iterators

Iterators act like pointers to elements inside STL containers. Every container provides begin() (pointing to the first element) and end() (pointing past the last element). Incrementing an iterator moves it to the next element. Iterators unify how you traverse different containers — the same pattern works for vectors, maps, sets, and more.

#include <iostream>
#include <vector>

int main() {
    std::vector<int> nums = {10, 20, 30, 40};
    for (auto it = nums.begin(); it != nums.end(); ++it) {
        std::cout << *it << " ";
    }
    return 0;
}
Try it Yourself →