insert
Syntax:
  #include <map>
  iterator insert( iterator i, const TYPE& pair );
  void insert( input_iterator start, input_iterator end );
  pair<iterator,bool> insert( const TYPE& pair );

The function insert() either:

  • inserts pair after the element at pos (where pos is really just a suggestion as to where pair should go, since sets and maps are ordered), and returns an iterator to that element.
  • inserts a range of elements from start to end.
  • inserts pair, but only if pair doesn't already exist. The return value is an iterator to the element inserted, and a boolean describing whether an insertion took place.

For example, the following code uses the insert() function to insert some data into a map:

  map<const char*, int> m;
  m.insert( make_pair("test",5) );