Insert a pair using function make_pair : map insert « map multimap « C++ Tutorial






#include <map>
#include <iostream>

using namespace std;

typedef map <int, string> MAP_INT_STRING;
typedef multimap <int, string> MMAP_INT_STRING;

int main ()
{
    MAP_INT_STRING mapIntToString;
    mapIntToString.insert (make_pair (-1, "Minus One"));

    cout << "The map contains " << mapIntToString.size ();
    cout << " key-value pairs. " << endl;
    cout << "The elements in the map are: " << endl;

    return 0;
}








23.6.map insert
23.6.1.Insert characters into map.
23.6.2.Use insert() to add an entry
23.6.3.Duplicate keys are not allowed in a map
23.6.4.Insert a pair using function make_pair
23.6.5.Insert a pair object directly
23.6.6.Insert using an array-like syntax for inserting key-value pairs
23.6.7.Insert key-value pairs into the map using value_type
23.6.8.use subscript operator to write value to a map
23.6.9.Insert value pair to map