map按value值查找——find_if的使用(转载)
1 #ifndef _CVALUEFIND_H_ 2 #define _CVALUEFIND_H_ 3 #include <string> 4 #include <algorithm> 5 #include <map> 6 7 8 class map_value_finder 9 { 10 public: 11 map_value_finder(const std::string &cmp_string):m_s_cmp_string(cmp_string){} 12 bool operator ()(const std::map<int, std::string>::value_type &pair) 13 { 14 return pair.second == m_s_cmp_string; 15 } 16 private: 17 const std::string &m_s_cmp_string; 18 }; 19 #endif
main
#include <iostream> #include <windows.h> #include <vector>