在 list<map<string, string>> 获取map中的(Key/Value)值
首先,我们先向map中添加些许key/Value
map<string, string> mapKV;
mapKV["1"] = "1";
mapKV["2"] = "2";
mapKV["3"] = "3";
mapKV["4"] = "4";
mapKV["5"] = "5";
mapKV["6"] = "6";
mapKV.insert(pair<string, string>("7", "7"));
mapKV.insert(make_pair("8", "8"));
再向list中添加map键值
list<map<string, string>> listMap;
listMap.push_back(mapKV);
循环获取集合中的 map里面的 Key/Value
for (auto listMapIt = listMap.begin(); listMapIt != listMap.end(); listMapIt++)
{
map<string, string> map_str_str = *listMapIt;
for (auto mapIter = map_str_str.begin(); mapIter != map_str_str.end(); ++mapIter) {
cout << mapIter->first.data() << ":" << mapIter->second.data() << endl;
}
}
效果如下: