Q:

Check if element exists in map c++

Is there any function to find if an element exists in a map (not a key).
For instance I have a map and want to find if a word is the second element of any pair from the map, and if so, what is its key.

A:

Maps are organized by key, so short of iterating over each element there is no way to do this.
Assuming you are searching for look_for, you can use the standard library's std::find_if:
auto it = std::find_if(map.begin(),
                       map.end(),
                       [&look_for](const auto& kv_pair) {
                            return kv_pair.second == look_for;
                       });
if (it != map.end()) {
    auto key = it->first;
    // ...
} else {
    // Value not found
    // ...
}

It is also possible to use a manual loop (std::find_if is often considered nicer, but here that might be overkill)
for (const auto& kv_pair : map)
    if (kv_pair.second == look_for)
        return kv_pair.first;
// If you reach this, the value isn't in your map

