Standard C++ Library Class Reference
operator++ (int);
Increments the insert iterator and returns *this.
Non-member Function
template <class Container, class Iterator>
insert_iterator<Container>
inserter (Container& x, Iterator i);
Returns an insert_iterator that will insert elements into container x at location i. This
function allows you to create insert iterators inline.
Example
#include <iterator>
#include <vector>
#include <iostream.h>
int main()
{
//Initialize a vector using an array
int arr[4] = {3,4,7,8};
vector<int> v(arr,arr+4);
//Output the original vector
cout << "Start with a vector: " << endl << " ";
copy(v.begin(),v.end(),ostream_iterator<int>(cout," "));
//Insert into the middle
insert_iterator<vector<int> > ins(v, v.begin()+2);
*ins = 5;
*ins = 6;
//Output the new vector
cout << endl << endl;
cout << "Use an insert_iterator: " << endl << " ";
copy(v.begin(),v.end(),ostream_iterator<int>(cout," "));
return 0;
}
Warnings
If your compiler does not support default template parameters, then you need to always supply
the Allocator template argument. For instance, you'll have to write:
vector<int, allocator>
instead of: