Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to find the implementation of key according to value by C++map

2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report