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
1#include <iostream>
2#include <vector>
3using namespace std;
4
5vector<int> myvector;
6
7for (vector<int>::iterator it = myvector.begin();
8 it != myvector.end();
9 ++it)
10 cout << ' ' << *it;
11cout << '\n';
12
1// EXAMPLE
2vector<string> vData;
3vData.push_back("zeroth");
4vData.push_back("first");
5vData.push_back("second");
6vData.push_back("third");
7
8std::vector<string>::iterator itData;
9
10for (itData = vData.begin(); itData != vData.end() ; itData++)
11{
12 auto ElementIndex = itData-vData.begin();
13 auto ElementValue = vData[ElementIndex]; // vData[ElementIndex] = *itData
14 cout << "[ElementIndex:" << ElementIndex << "][ElementValue:" << ElementValue << "]\n";
15}
16
17/* HEADER(S)
18#include <vector>
19#include <iostream>
20using namespace std;
21*/
1// vector::begin/end
2#include <iostream>
3#include <vector>
4
5int main ()
6{
7 std::vector<int> myvector;
8 for (int i=1; i<=5; i++) myvector.push_back(i);
9
10 std::cout << "myvector contains:";
11 for (std::vector<int>::iterator it = myvector.begin() ; it != myvector.end(); ++it)
12 std::cout << ' ' << *it;
13 std::cout << '\n';
14
15 return 0;
16}