Define string-string map and loop through the value key-pair : map « Map Multimap « C++






Define string-string map and loop through the value key-pair

  
 

#include <iostream>
#include <map>
#include <string>

using namespace std;

int main( ) {

   map<string, string> strMap;

   strMap["Monday"]    = "1";
   strMap["Tuesday"]   = "2";
   strMap["Wednesday"] = "3";
   strMap["Thursday"]  = "4";
   strMap["Friday"]    = "5";
   strMap["Saturday"]  = "6";
   strMap.insert(pair<string, string>("Sunday", "7"));

   for (map<string, string>::iterator p = strMap.begin( );
      p != strMap.end( ); ++p ) {
         cout << "English: " << p->first<< ", #: " << p->second << endl;
   }

   cout << endl;

}

 /* 
English: Friday, #: 5
English: Monday, #: 1
English: Saturday, #: 6
English: Sunday, #: 7
English: Thursday, #: 4
English: Tuesday, #: 2
English: Wednesday, #: 3


 */       
    
  








Related examples in the same category

1.Demonstrating an STL map
2.Use string as the key and value in a map
3.Declare a char int map
4.Create string float map
5.Multiple map
6.Store objects in a map
7.Add user-defined object to map, loop through the map and output
8.Computing an inner product of tuples represented as maps
9.Use a map to create a phone directory.
10.Get the size of a map
11.Put value to map with assignment