use transform() to create map from two arrays : transform « Map Multimap « C++






use transform() to create map from two arrays

  
#include <algorithm>
#include <iostream>
#include <map>
#include <utility>

using namespace std;

int main( )
{
   const char* word[] = { "A", "B", "C", "D","E" };
   const char* clue[] = { "a", "b","c", "d","e" };

   map<string,string> dictionary1;
   transform( word, word+sizeof(word)/sizeof(word[0]), clue,inserter( dictionary1, dictionary1.end() ),make_pair<string,string> );
   cout << "There are " << dictionary1.size() << " words in the dictionary\n\n";

}
  
    
  








Related examples in the same category

1.Transform vector of user-defined objects to a multi-map
2.Use transform to fill a map from a vector of user-defined object