【发布时间】:2020-07-22 09:44:53
【问题描述】:
我必须在 C++ 中的无序映射上运行一个循环(在 t 上循环),每次运行循环时,无序映射都会更新。但我想做的是,每次运行循环时都从一个空地图开始。如何初始化一个空的无序地图?
while (t--){
unordered_map<int, int> freq;
//perform various insertions and deletions in the map
//print all the elements in the map
}
【问题讨论】:
-
在您发布的代码中,您已经从一张空地图开始。每当你添加一个 key 元素时,它的 value 元素都会被初始化,对于 int 值意味着它们将被设置为 0。
-
无处不在的lambdas
标签: c++ dictionary data-structures unordered-map