shadowm

Untitled

Apr 14th, 2012
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. std::map<keyT, valueT> foo; // ...
  2. keyT key; // ...
  3.  
  4. std::map<keyT, valueT>::const_iterator item = foo.find(key);
  5.  
  6. if(item != foo.end()) {
  7.     // The iterator is valid, so we can dereference the pointed item directly.
  8.     const std::pair<keyT, valueT>& real_item = *item;
  9.     // And do something with it.
  10. } else {
  11.     // The iterator is not valid, so that means there's no element whose key is 'key'
  12.     // in the 'foo' container.
  13. }
Advertisement
Add Comment
Please, Sign In to add comment