Difference between revisions of "CPP/STL/MultiMap"

From ProgrammingExamples
< CPP
Jump to: navigation, search
(Created page with '==MultiMap.cpp== <source lang="cpp"> #include <iostream> #include <map> int main(int argc, char *argv[]) { std::multimap <int, double> MyMap; //create a mapping from "t…')
 
m
 
(One intermediate revision by one other user not shown)
Line 6: Line 6:
 
int main(int argc, char *argv[])
 
int main(int argc, char *argv[])
 
{
 
{
 
 
   std::multimap <int, double> MyMap;
 
   std::multimap <int, double> MyMap;
 
    
 
    
   //create a mapping from "testone" to 111
+
   // Create a mapping from "testone" to 111
   MyMap.insert(std::pair<int, double>(1, 1.2));
+
  MyMap.insert(std::make_pair(1, 1.2));
 
+
  // This is equivalent to:   MyMap.insert(std::pair<int, double>(1, 1.2));
   //create an iterator
+
 
 +
   // Create an iterator
 
   std::map<int, double>::iterator iter;
 
   std::map<int, double>::iterator iter;
  

Latest revision as of 07:05, 15 June 2011

MultiMap.cpp

#include <iostream>
#include <map>
 
int main(int argc, char *argv[])
{
  std::multimap <int, double> MyMap;
 
  // Create a mapping from "testone" to 111
  MyMap.insert(std::make_pair(1, 1.2));
  // This is equivalent to:   MyMap.insert(std::pair<int, double>(1, 1.2));  
 
  // Create an iterator
  std::map<int, double>::iterator iter;
 
  iter = MyMap.find(1);
 
  if(iter == MyMap.end())
  {
    std::cout << "Not found." << std::endl;
  }
  else
  {
      std::cout << "Found: " << iter->second << std::endl;	
  }
 
  return 0;
}