Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- std::map<keyT, valueT> foo; // ...
- keyT key; // ...
- std::map<keyT, valueT>::const_iterator item = foo.find(key);
- if(item != foo.end()) {
- // The iterator is valid, so we can dereference the pointed item directly.
- const std::pair<keyT, valueT>& real_item = *item;
- // And do something with it.
- } else {
- // The iterator is not valid, so that means there's no element whose key is 'key'
- // in the 'foo' container.
- }
Advertisement
Add Comment
Please, Sign In to add comment