Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 31st, 2012  |  syntax: None  |  size: 0.27 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. check if a key is found in a map c   and obtains it
  2. std::map<int, int> m;
  3.  
  4. m[0] = 1;
  5. m[1] = 2;
  6.  
  7. if (m.count(0))
  8. {
  9.     std::cout << "value=" << m[0] << "n";
  10. }
  11.        
  12. std::map<int, int>::iterator i = m.find(0);
  13. if (i != m.end())
  14. {
  15.     std::cout << "value=" << i->second << "n";
  16. }