How can I check if an element is in map keys in C++?
<p>I am wonder if there is a way I can check if an element is included in map keys. For example:</p>

<pre><code>#include&lt;iostream&gt;
#include&lt;map&gt;

using namespace std;

int main()
{

map&lt;char, int&gt; mymap;

mymap['a'] = 1;
mymap['b'] = 2;
mymap['z'] = 26;

// I want to check if 'b' is one of the keys in map mymap.

    return 0;
}
</code></pre>

<p>Elements 'a', 'b' and 'z' are the keys of map mymap. I want a command that will return <code>true</code> if element is in keys of a map and <code>false</code> if the elements is not in keys of a map.
I looked around, but could find a quick build-in method that does this. Did I miss anything? Is there a such a method?</p>

<p>Here is a long way that gets me my desired outcome:</p>

<pre><code>#include&lt;iostream&gt;
#include&lt;map&gt;

using namespace std;

bool check_key(map&lt;char, int&gt; mymap, char key_val);

int main()
{

map&lt;char, int&gt; mymap;

mymap['a'] = 1;
mymap['b'] = 2;
mymap['z'] = 26;

char key_val = 'h';

cout&lt;&lt;mymap.find('z')-&gt;first&lt;&lt;endl;

cout&lt;&lt;"checking "&lt;&lt; check_key(mymap, 'h')&lt;&lt;endl;
cout&lt;&lt;"checking "&lt;&lt; check_key(mymap, 'b')&lt;&lt;endl;

    return 0;
}

bool check_key(map&lt;char, int&gt; mymap, char key_val){

    for (map&lt;char, int&gt;::const_iterator it = mymap.begin(); it != mymap.end(); ++it ){
        if (key_val == it-&gt;first){
            return true;
        }

    }
    return false;

}
</code></pre>

<p>Thank You in Advance</p>
