从c ++中的地图读取集合
read set from map in c++
这是一个非常愚蠢的问题,但不知何故我无法解决。
我有一个映射,其键是字符串并且设置了值,我想遍历值并打印它,例如
std::map<std::string, std::set<std::string>> test_map_set
for (auto it_map = test_map_set["test"].begin(); it_mpa != test_map_set["test"].begin(); it_map ++ )
{
auto it = it_map->second; ===> Here I am getting error that it has no member second
then iterate through set
}
我的问题是如何遍历集合?
确实std::string
没有成员second
。
自从有了 c++11,生活就轻松多了:
std::map<std::string, std::set<std::string>> test_map_set
for (std::string& set_element : test_map_set["test"])
{
}
删除:
auto& test = test_map_set["test"];
for (auto it = test.begin(); it!= test.end();)
{
if (it->length()==5)
it = test.erase(it);
else
++it;
}
这将删除所有 5 个字符的字符串
这是一个非常愚蠢的问题,但不知何故我无法解决。
我有一个映射,其键是字符串并且设置了值,我想遍历值并打印它,例如
std::map<std::string, std::set<std::string>> test_map_set
for (auto it_map = test_map_set["test"].begin(); it_mpa != test_map_set["test"].begin(); it_map ++ )
{
auto it = it_map->second; ===> Here I am getting error that it has no member second
then iterate through set
}
我的问题是如何遍历集合?
确实std::string
没有成员second
。
自从有了 c++11,生活就轻松多了:
std::map<std::string, std::set<std::string>> test_map_set
for (std::string& set_element : test_map_set["test"])
{
}
删除:
auto& test = test_map_set["test"];
for (auto it = test.begin(); it!= test.end();)
{
if (it->length()==5)
it = test.erase(it);
else
++it;
}
这将删除所有 5 个字符的字符串