Iterators & Range Traversal

🟡 Intermediate

📖 Definition

Iterators are generalized pointer objects that connect STL containers with generic algorithms. Standard iterators include Input, Output, Forward, Bidirectional, and RandomAccess iterators (supporting .begin(), .end(), .cbegin(), .cend()).

💡 Code Example

#include <iostream>
#include <vector>

int main() {
    std::vector<int> v{1, 2, 3, 4};

    for (std::vector<int>::const_iterator it = v.cbegin(); it != v.cend(); ++it) {
        std::cout << *it << " ";
    }
    std::cout << "\n";
    return 0;
}