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;
    }

  • 相关阅读:
    C++ 与 C 的预处理能力
    unicore32linuxgcc 预定义宏
    内核中的原子上下文
    ConText
    PREEMPT_ACTIVE
    对象和类
    java的getClass()函数
    堆栈以及对象的引用
    public、protected、default、private作用域
    android 环境变量搭建
  • 原文地址:https://www.cnblogs.com/huochangjun/p/3125397.html
Copyright © 2011-2022 走看看