Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个带有字符串的地图,它返回一个整数。我希望将地图实例的整数初始化为 0。我该怎么做?例如:
std::map<std::string, int> x;
我希望将所有整数初始化为 0 作为起点。我该怎么做呢?
简单地访问某个键将默认初始化其对应的值。对于int,这相当于将其设置为 0:
int
x["foo"];
虽然,老实说,它会更容易阅读为x["foo"] = 0;.
x["foo"] = 0;