map<char,int> m;
m['a'] = 10;
m['b'] = 20;
m['c'] = 30;
pair<map<char,int>::iterator,map<char,int>::iterator> p = m.equal_range('c');
if(p.first == m.end() && p.second == m.end()) // or if(p.first==p.second==m.end())
report_key_is_not_in_map();
I do this way, it seem a little complex, more simple way?
how to see if a key in a map
Hi
How about this?
map<char,int> m;m['a'] = 10;m['b'] = 20;m['c'] = 30;if (m.find('c') == m.end()){ report_key_is_not_in_map();}
How about this?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement