C++10.3.8 map对象的迭代遍历---begin 和end

来源:互联网 发布:lm555数据手册 编辑:程序博客网 时间:2024/05/16 13:04

简介

========================================================================================

  • 与其他容器一样,map容器同样提供begin和end运算,以生成用于遍历整个容器的迭代器。
map<string,int>::const_iterator map_it = word_count.begin();while(map_it!=word_count.end()){   cout<<map_it->first<<endl;   cout<<map_it->second<<endl;   ++map_it;}
  • 这个单词统计程序依据字典顺序输出单词,在使用迭代器遍历map 容器时,迭代器指向的元素按键的升序排列。
0 0
原创粉丝点击