example2_const_containers.cpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
#include <iostream>
#include <vector>

int main() {
    const std::vector<int> numbers = {1, 2, 3, 4, 5};

    // Range-based for loop with a const reference
    for (const int& n : numbers) {
        std::cout << n << " ";
    }
    std::cout << std::endl;

    return 0;
}
Back to range-based