unorderedmap相等
时间: 2023-09-13 20:13:33 浏览: 116
要判断两个 `unordered_map` 是否相等,可以使用 `==` 运算符进行比较。以下是一个示例代码:
```cpp
#include <iostream>
#include <unordered_map>
int main() {
std::unordered_map<int, std::string> map1 = {{1, "Apple"}, {2, "Banana"}};
std::unordered_map<int, std::string> map2 = {{1, "Apple"}, {2, "Banana"}};
std::unordered_map<int, std::string> map3 = {{1, "Apple"}, {3, "Orange"}};
if (map1 == map2) {
std::cout << "map1 and map2 are equal" << std::endl;
} else {
std::cout << "map1 and map2 are not equal" << std::endl;
}
if (map1 == map3) {
std::cout << "map1 and map3 are equal" << std::endl;
} else {
std::cout << "map1 and map3 are not equal" << std::endl;
}
return 0;
}
```
输出结果应为:
```
map1 and map2 are equal
map1 and map3 are not equal
```
以上代码演示了如何使用 `==` 运算符判断两个 `unordered_map` 是否相等。
阅读全文
相关推荐


















