c++ - Access STL map by value -
i have problem accessing map value. not want access value using find("string_value")
, 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 find()
accepts const value while it_->second
not. if map had value, if condition fails. there no compile time errors though. help?
you should boost, bimap
class.
http://www.boost.org/doc/libs/1_42_0/libs/bimap/doc/html/index.html
this let make map both sides searchable.
regular stl maps searchable on key, not value.
Comments
Post a Comment