map<string,list<string>> 便利
时间: 2023-11-10 13:54:11 浏览: 51
您好!要遍历 `map<string, list<string>>`,您可以使用迭代器来逐个访问其中的键值对。以下是一个示例代码:
```c++
#include <iostream>
#include <map>
#include <list>
#include <string>
int main() {
std::map<std::string, std::list<std::string>> myMap;
// 添加一些数据到 map
myMap["key1"] = {"value1", "value2", "value3"};
myMap["key2"] = {"value4", "value5"};
myMap["key3"] = {"value6"};
// 遍历 map
for (auto it = myMap.begin(); it != myMap.end(); ++it) {
std::cout << "Key: " << it->first << std::endl;
std::cout << "Values: ";
for (const auto& value : it->second) {
std::cout << value << " ";
}
std::cout << std::endl;
}
return 0;
}
```
输出结果将会是:
```
Key: key1
Values: value1 value2 value3
Key: key2
Values: value4 value5
Key: key3
Values: value6
```
希望能对您有所帮助!如有任何疑问,请随时提出。