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}