How to find the implementation of key according to value by C++map
Today, I will talk to you about C++map how to find the implementation of key according to value. Many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.
Flyfish
Test the required header file
# include # include
Initial
Std::map t; t.insert (std::make_pair (1, "a")); t.insert (std::make_pair (2, "b")); t.insert (std::make_pair (3, "c")); t.insert (std::make_pair (4, "d"))
Find value according to key
Std::string s = "; auto it = t.find (2); if (it! = t.end ()) {s = (* it) .second;}
Find key lambda mode according to value
Std::string s = "c"; auto find_item = std::find_if (t.begin (), t.end (), [s] (const std::map::value_type item) {return item.second = = s;}); int n = 0; if (findkeeper itemized = t.end ()) {n = (* find_item) .first;}
How to find the object of key function according to value
Class finder {public: finder (const std::string & cmp_string): scmp_string {} bool operator () (const std::map::value_type & item) {return item.second = = slots;} private: const std::string & slots;}; / / call int n = 0 return item.second auto it = std::find_if (t.begin (), t.end (), finder ("d")); if (it! = t.end ()) {n = (* it). First }
The above C++ map according to value to find the implementation of key is the editor to share with you all the content, I hope to give you a reference, but also hope that you support us.
After reading the above, do you have any further understanding of how C++map can find the implementation of key based on value? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.