You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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;
}