std::unordered_map 怎么查找
时间: 2023-04-04 10:02:45 浏览: 96
并查集全数据类型模板(内部用unordered_map实现)
std::unordered_map 可以使用 find() 函数进行查找,例如:
std::unordered_map<std::string, int> myMap;
myMap["apple"] = 1;
myMap["banana"] = 2;
auto it = myMap.find("apple");
if (it != myMap.end()) {
std::cout << "apple is found with value " << it->second << std::endl;
} else {
std::cout << "apple is not found" << std::endl;
}
输出结果为:
apple is found with value 1
阅读全文