C++ STL map 遍历


#include
#include
#include
using namespace std;

int main()
{
      map  m;
      m["a"]=1;
      m["b"]=2;
      m["c"]=3;
      map::iterator it;
      for(it=m.begin();it!=m.end();++it)
            cout<<"key: "<first <<" value: "<second<       return    0;
}

 
map::iterator it;    定义一个迭代指针it。 
it->first 为索引键值,it->second 为值。

你可能感兴趣的:(算法)