Recently I had been learning maps in C++ and I came across various problems where I need to check if a "KEY" exists for a given value. In JAVA we can do so by following code snippet -
hash_map.containsValue(VALUE); // Returns true if there is a key for the value, as false
I am looking for similar stuff in C++. I have found resources that can check for existing of "KEY" like :
mp.count(k); //will return 0 if a key "k" not exists, else it's count
But how to do it for "VALUE NOT KEY"?
In C++ there is no such direct method to check if a given map contains the value. One will have to iterate through the entire map and check if it contains the value or note. It can be achieved as follows
Hope it helps.