1std::vector<int> vec_of_ints(10, 1); // 10 ints all with value 1
2for (int i : vec_of_ints) { // use auto for more complex types
3 std::cout << vec_of_ints.at(i) << " ";
4}
5std::cout << std::endl;
1vector<int> myVector;
2
3myVector.push_back(1);
4myVector.push_back(2);
5myVector.push_back(3);
6myVector.push_back(4);
7
8for(auto x: myVector){
9 cout<< x << " ";
10
11}
12
13vector<pair<int,int>> myVectorOfPairs;
14
15myVectorOfPairs.push_back({1,2});
16myVectorOfPairs.push_back({3,4});
17myVectorOfPairs.push_back({5,6});
18myVectorOfPairs.push_back({7,8});
19
20for(auto x: myVectorOfPairs){
21 cout<< x.first << " " << x.second << endl;
22
23}
24
25
26
27
28
29
30
1for(std::vector<T>::size_type i = 0; i != v.size(); i++) {
2 v[i].doSomething();
3}