I have a problem accessing a Map by value. I do not want to access the value using find("string_value"), but as find(s) while string s="string_value". See below:
map<string, string> my_map; string s; map<string, string>::iterator it_; for(it_ = my_map.begin(); it_!= my_map.end(); it_++) { s = it_->second; if (my_map.find(s) != my_map.end()) cout << my_map.find(s)->second << endl; } My initial guess is that find() accepts const value while it_->second is not. So even if my map had the value, the if condition fails. There were no compile time errors though. Any help?
std::mapmodels a mapping from the key to the value - it's a one way relationship. You can't use the value to get the corresponding key.find(s)sort of feature doesn`t exist using map. The best bet would be to use boost bimap. However, am not sure if we can have a custom find method that accomplishes what I needed.