c++ mapset
时间: 2023-08-28 16:17:57 浏览: 203
C++ 中的 `map` 和 `set` 是两个常用的容器类,用于存储和管理元素。
`map` 是一种关联容器,其中的元素按照键值对的形式存储。每个键都是唯一的,而且按照特定的排序规则进行存储。你可以使用键来访问对应的值。例如:
```cpp
#include <iostream>
#include <map>
int main() {
std::map<std::string, int> ages;
// 插入键值对
ages["John"] = 25;
ages["Lisa"] = 30;
ages["Mike"] = 35;
// 访问值
std::cout << "Mike's age is: " << ages["Mike"] << std::endl;
return 0;
}
```
`set` 是一种关联容器,其中的元素按照特定的排序规则进行存储。每个元素都是唯一的,并且不能直接修改。你可以使用迭代器来访问和遍历元素。例如:
```cpp
#include <iostream>
#include <set>
int main() {
std::set<int> numbers;
阅读全文
相关推荐















