#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> vectorObject;
int i;
for(i = 0; i <10; i++)
vectorObject.push_back(i);
cout << "Vector printed forwards:\n";
vector<int>::iterator p = vectorObject.begin();
while(p != vectorObject.end()) {
cout << *p << " ";
p++;
}
cout << "\n";
cout << "Vector printed backwards:\n";
p = vectorObject.end();
while(p != vectorObject.begin()) {
p--; // decrement iterator before using
cout << *p << " ";
}
return 0;
}
|