要向unordered_map中增加数据,可以使用insert()方法或者直接使用方括号运算符[]来进行插入。

使用insert()方法:

std::unordered_map<int, std::string> myMap;
myMap.insert(std::make_pair(1, "one"));
myMap.insert(std::make_pair(2, "two"));

使用方括号运算符[]:

std::unordered_map<int, std::string> myMap;
myMap[1] = "one";
myMap[2] = "two";

以上两种方法都可以将键值对插入到unordered_map中。

unordered_map如何增加数据

原文地址: https://www.cveoy.top/t/topic/ie7f 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录