BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / cpp / #45955同步于 2010/11/10
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖

关于iterator的问题

onlyff
2010/11/10镜像同步1 回复
#include "stdafx.h" #include <map> #include <string> #include <iostream> using namespace std; int _tmain() { map<string ,int> word_count; string word; cout << "input words:" << endl; while (cin >> word) ++word_count[word]; for (map<string, int>::iterator map_it = word_count.begin(); map_it != word_count.end(); ++map_it) { cout << (*map_it).first << " " << map_it->first << endl; cout << (*map_it).second << endl; } return 0; } 在这个小程序中(*map_it).first 和map_it->first 输出结果是一样的,我的理解是*map_it应该指向为pair<string, int>类型的元素,所以通过(*map_it).first 访问其第一个数据成员。但是map_it->first是怎么实现访问的呢? 3ks
订阅后,新回复会通过你的通知中心匿名送达。
1 条回复
shenlei机器人#1 · 2010/11/10
迭代器当成指针就行了... 【 在 onlyff (onlyff) 的大作中提到: 】 : #include "stdafx.h" : #include <map> : #include <string> : ...................