Ex11_8.cpp
上传用户:wuzhousb
上传日期:2022-07-12
资源大小:380k
文件大小:1k
源码类别:

书籍源码

开发平台:

Visual C++

  1. //【例11.8】我国部分省份与面积映射关联容器类的演示。
  2. #include<iostream>
  3. #include<string>
  4. #include<functional>
  5. #include<map>
  6. using namespace std;
  7. typedef map<string,double,less<string> > mappro;  //> >之间必须有空格
  8. int main(){
  9. int  i;
  10. string provinces[]={"Jiangsu","Zhejiang","Anhui","Henan","Xinjiang"};
  11. double areas[]={10.26,10.18,13.96,16.7,166};
  12. mappro mapprovinces;
  13. mappro::iterator iter;
  14. for(i=0;i<5;i++) mapprovinces[provinces[i]]=areas[i];
  15. mapprovinces.insert(mappro::value_type("Guangdong",17.98));
  16. mapprovinces.insert(mappro::value_type("Shanxi",20.58));
  17. mapprovinces.insert(mappro::value_type("Heilongjiang",46));
  18. mapprovinces.insert(mappro::value_type("Taiwan",3.6));
  19. mapprovinces.insert(mappro::value_type("Yunnan",39.4));
  20. for(iter=mapprovinces.begin();iter!= mapprovinces.end();iter++)
  21. cout<<iter->first<<'t'<<iter->second<<'n';
  22. return 0;
  23. }