如何查找给定的键是否存在于C ++ std :: map中

问题描述:

我想检查值是否在地图中,有时不能做到:

I'm trying to check if value is in a map and somewhat can't do it:

typedef map<string,string>::iterator mi;
map<string, string> m;
m.insert(make_pair("f","++--"));
pair<mi,mi> p = m.equal_range("f");//I'm not sure if equal_range does what I want
cout << p.first;//I'm getting error here

使用 map :: find

if ( m.find("f") == m.end() ) {
  // not found
} else {
  // found
}