zoukankan      html  css  js  c++  java
  • C++总结笔记(十一)常见容器map

    #include<iostream>
    #include<map>
    #include<string>
    using namespace std;

    void operMap()
    {
     map<int,string> studentMap;
     studentMap[1] = "A";
     studentMap[2] = "B";
     studentMap[3] = "C";
     studentMap[4] = "D";
     studentMap[5] = "E";
     studentMap.insert(pair<int,string>(6,"F"));
     studentMap.insert(pair<int,string>(7,"G"));

     map<int,string>::iterator i;
     for(i=studentMap.begin();i!=studentMap.end();i++)
     {
      cout<<i->first<<"|"<<i->second<<endl;
     }

     string value = studentMap[4];
     cout<<"value="<<value<<endl;
     //******************************
     studentMap.erase(5);
     cout<<"After erase:"<<endl;
     map<int,string>::iterator ii;
     for(ii=studentMap.begin();ii!=studentMap.end();ii++)
     {
      cout<<ii->first<<"|"<<ii->second<<endl;
     }

     cout<<"After erase2:"<<endl;
     map<int,string>::iterator i1;
     //studentMap.erase(studentMap.begin(),--studentMap.end());


     for(i1=studentMap.begin();i1!=studentMap.end();i1++)
     {
      cout<<i1->first<<"|"<<i1->second<<endl;
     }

     //*********************************
     cout<<"Find the element:";
     studentMap.find(6);
     cout<<studentMap.find(6)->second<<endl;
    }

    int main()
    {
     operMap();
     return 0;
    }

  • 相关阅读:
    node.js
    重学css
    MongoDB
    改写radio样式
    js系统总结
    vue+koa2商城实战学习笔记
    在Linux上配置unixODBC和FreeTDS访问MS SQL Server
    ASP.NET中文件上传下载方法集合
    SQL SERVER 分页查询存储过程
    Delphi7调用C#写的Webservice
  • 原文地址:https://www.cnblogs.com/huochangjun/p/3125397.html
Copyright © 2011-2022 走看看