programming-examples/c++/Others/Access a vector using an iterator..cpp
2019-11-15 12:59:38 +01:00

26 lines
393 B
C++

Access a vector using an iterator.
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> v;
int i;
for(i = 0; i <10; i++)
v.push_back(i);
for(i = 0; i <10; i++)
cout << v[ i ] << " ";
cout << endl;
vector<int>::iterator p = v.begin();
while(p != v.end()) {
cout << *p << " ";
p++;
}
return 0;
}