iterator.cpp (444B)
1 #include <vector> 2 #include <iostream> 3 4 int main() { 5 std::vector<int> vec = {1,2,10,3}; 6 7 for (int value : vec) 8 std::cout << value << std::endl; 9 10 // same thing, different syntax 11 for (auto it = vec.begin(); it != vec.end(); ++it) 12 std::cout << *it << std::endl; 13 14 // basically, use the first option for iteration without index 15 // if you need the index then use standard for loop, not range based for loop 16 17 18 }