p2("W", "world");和p3("W", "wow");
假如我有两个相同的指标,如代码中两个"W",在for循环中输出时却只输出到p2,p3就被忽略了,为什么啊?迭代器不应该只是迭代每一个位置吗,和命名怎么会有关系?
pair<string, string> p1("H", "hello");
pair<string, string> p2("W", "world");
pair<string, string> p3("W", "wow");
for (map<string, string>::iterator beg = map1.begin();
beg != map1.end(); beg++)
{
cout << beg->first << endl;
cout << beg->second << endl;
cout << endl;
}
输出如下: