什么是 freq_table[field_pm_value] = map<string, int>();方法?

What does freq_table[field_pm_value] = map<string, int>(); means?

我正在查看一些代码,但无法理解以下语法:

freq_table[field_pm_value] = map<string, int>();

我对这里发生的事情感到困惑 "map string, int()"。 freq_table 属于

类型
map<string, map<string, int> >& freq_table 

完整代码为https://github.com/vishalsingh8989/Star-Cubing-Algorithm/blob/master/src/csvreader.cpp

谢谢

freq_table[field_pm_value] = map<string, int>();

这会创建一个从 stringint 的新空 map,然后将其复制到 field_pm_value[=19= 的 freq_table 条目]

如果 freq_table 没有 field_pm_value 的条目,则会为其创建一个新条目。

Map

Maps are associative containers that store elements formed by a combination of a key value and a mapped value, following a specific order.

这个结构类似于: 在一个房子里,你有不同的房间,代表你的“外部地图容器”map<string, map<string, int> >& freq_table,在每个房间里,你都有独特的家具和它们的数量。这些家具在“内图”中定义。

由于std::map有唯一的钥匙,所以你的房子里不能有2间卧室,也不能有2张床在同一个房间里。

在你的情况下,你正在检查你的“房间”中是否已经有家具,否则你将构建一个空的“房间”。

我很抱歉这个尴尬的类比,尽管我希望它能有所帮助。