C++ Multimap运用实例—查找元素
#include <map> #include <iostream> #include <algorithm> #include <utility> using namespace std; int main() { map<float, float> map1 = { {1,7},{2,8},{3,9},{4,8},{5,6},{6,1},{7,3} }; auto posKey = map1.find(3.0); if (posKey != map1.end()) { cout << "" << posKey->first << " " << posKey->second << endl; } auto posVal = find_if(map1.begin(),map1.end(), [](const pair<float, float>& elem1) { return elem1.second == 3.0; }); if (posVal != map1.end()) { cout << posVal->first << " " << posVal->second << "" << endl; } system("pause"); return 0; }
3 9
7 3
请按任意键继续. . .
代码参考:C++标准库(第2版)