Create insert_iterator to element 2 : insert_iterator « STL Algorithms Iterator « C++ Tutorial






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








30.4.insert_iterator
30.4.1.Create insert_iterator to element 2
30.4.2.insert iterator and remove_copy_if
30.4.3.insert_iterator from vector: set the position
30.4.4.Demonstrate insert_iterator