7
例如,计算在一本书的话,我看到有人发生根本写道:在地图<string, int>,是否保证int被初始化为零?
map<string, int> count;
string s;
while (cin >> s) count[s]++;
这是这样做的正确方法是什么?我在我的机器上测试过,看起来如此。但是初始化为零保证了吗?如果不是,我会想象一个这样的代码:
map<string, int> count;
string s;
while (cin >> s)
if (count.find(s) != count.end()) count[s]++;
else count[s] = 1;
谢谢!你有没有提及你的观点? –