Labs ICT
Pro Login

Iterators

1 min read | C++ Tutorial

Want the full learning experience?

Get structured courses, certificates, projects, and instructor support with LabsICT Pro.

Explore Pro Courses

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;
}