iterate const vector

#include <iostream>
#include <vector>

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

    for (auto it = numbers.begin(); it != numbers.end(); ++it) {
        std::cout << *it << " ";
    }

    return 0;
}

Explanation:

  1. Include Necessary Headers: The #include directives bring in the required header files (iostream and vector) for input/output operations and vector usage.

  2. Main Function: The main() function serves as the entry point for the program.

  3. Create a Constant Vector:const std::vector<int> numbers = {1, 2, 3, 4, 5}; initializes a constant vector named numbers with integers 1 through 5.

  4. Iterating Through the Vector: The for loop initiates an iterator (it) at the beginning of the numbers vector (numbers.begin()) and continues until it reaches the end (numbers.end()). During each iteration, it prints the value pointed to by the iterator (*it) using std::cout.

  5. Output: The program prints each element of the vector separated by a space, displaying 1 2 3 4 5.