map是STL的一个关联容器,它提供一对一的hash。
第一个可以称为关键字(key),每个关键字只能在map中出现一次;
第二个可能称为该关键字的值(value);
我们了解到map之后就可以操作他了
include<iostream>
include<map>
using namespace std;
int main(){
//先随便声明个map,声明他的迭代器
map<int,int> m;
for(int i = 0; i < 5; ++i){
m[i] = i * 1000;
}
map<int,int>::iterator it;
//第一种
for(auto &t : m){
cout<<t.first<<t.second<<endl;
}
//第二种
for(iter = m.begin(); iter != m.end(); ++iter){
cout<<iter->first<<iter->second<<endl;
}
//第三种
while(iter != m.end()){
cout<<iter->first<second<<endl;
++iter;
}
}