本文共 774 字,大约阅读时间需要 2 分钟。
#include #include #include #include #include using namespace std;class finder{public: finder(const std::string &cmp_string) :s_(cmp_string){} bool operator ()(const std::map ::value_type &item) { return item.second == s_; }private: const std::string &s_;};int main(){ map t; t.insert(std::make_pair(1, "cpu_syscall_pid")); t.insert(std::make_pair(2, "cpu_syscall_cpu")); t.insert(std::make_pair(3, "cpu_syscall_sys")); t.insert(std::make_pair(4, "cpu_contxt_pid")); int n = 0; auto it = std::find_if(t.begin(), t.end(), finder("cpu_syscall_pid")); if (it != t.end()) { n = (*it).first; } cout << "n:" << n << endl; return 0;}
转载于:https://www.cnblogs.com/muahao/p/8854817.html