#include <iostream>
#include <iterator>
#include <vector>
using namespace std;
int main()
{
vector<int> vectorObject;
vector<int>::iterator itr;
int i;
for(i = 0; i <5; i++)
vectorObject.push_back( i );
cout << "Original contents of vectorObject: ";
itr = vectorObject.begin();
while(itr != vectorObject.end())
cout << *itr++ << " ";
cout << endl;
itr = vectorObject.begin();
itr += 2; // point to element 2
insert_iterator<vector<int> > i_itr(vectorObject, itr); // create insert_iterator to element 2
*i_itr++ = 100; // insert rather than overwrite
*i_itr = 200;
cout << "vectorObject after insertion: ";
itr = vectorObject.begin();
while(itr != vectorObject.end())
cout << *itr++ << " ";
return 0;
}
|