Ton*_*Gin 2 c++ dictionary stl
我想知道为什么我的输出看起来像这样:
This : 1
a : 4
is : 2
just : 3
test : 5
Run Code Online (Sandbox Code Playgroud)
当我的代码看起来像这样:
map<string, int> wordCount;
wordCount["This"] = 1;
wordCount["is"] = 2;
wordCount["just"] = 3;
wordCount["a"] = 4;
wordCount["test"] = 5;
for (map<string, int>::iterator it = wordCount.begin();
it != wordCount.end(); it++) {
cout << it->first << " : " << it->second << endl;
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,地图以随机顺序存储对象吗?
地图按排序顺序存储内容."This"之前出现的原因"a"是大多数(如果不是所有的字符集)都出现在之前,因此在此之前,因为不考虑字符串的长度.'T''a''T' < 'a'"This""a"
如果你换This到this那么你会得到
a : 4
is : 2
just : 3
test : 5
this : 1
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
61 次 |
| 最近记录: |