Map for string key and integer value : pair « Map Multimap « C++






Map for string key and integer value

   
#include <iostream>
#include <map>
#include <string>
using namespace std;

int main()
{
   map<string, int, less<string> > name_age;

   name_age["A"] = 7;
   name_age["B"] = 39;
   name_age["C"] = 14;
   cout << "A is  "
        << name_age["A"]
        << " years old." << endl;
}
  
    
    
  








Related examples in the same category

1.Inserting pairs of object into map
2.print the maximum number of pairs that DateMap can hold
3.Use map to store the value of the month name and its day number
4.Iterating over the elements of the map and using the current pair option and second elements.
5.Put pairs to map with insert
6.for each basic
7.Computing the Median 1
8.Sort a list of int and string pairs
9.Pass output message function to for_each function