C ++ is determined whether the value stored in the map key

Determining whether the value stored in the map key

In the map of the course will be based on the existence of a key in the map to decide whether to operate inside the assignment, describes two ways here
1.find function

iterator find ( const key_type& key );

If the key is present, then find the corresponding key iterator returns, if the key does not exist, find the end of the returned iterator end ().

if (map.find(key) == map.end())
    cout << "False" << endl;

2.count function

count the number of statistical functions for key value appears in the map, map the key must be unique, so if a return key is present, there is no return to zero.

if (map.count(key) == 0)
    cout << "False" << endl;
Released three original articles · won praise 0 · Views 12

Guess you like

Origin blog.csdn.net/qq_31737075/article/details/105034778