zoukankan      html  css  js  c++  java
  • 语艺杂谈1 – MAP赋值与插入

    MAP赋值和插入,对于相同ID的处理方式不同,前者为替换 后者为插入失败

    #include <map>
    #include <string>
    #include <iostream>
    using namespace std;
    int main()
    {
       map<int, string> mapStudent;
       pair<map<int, string>::iterator, bool> Insert_Pair;
       mapStudent[1] = "student_one";
       mapStudent[1] = "student_one2";   
       
       cout << "====================MAP  赋值测试=====================
    " <<endl ;
       map<int, string>::iterator  iter;
       for(iter = mapStudent.begin(); iter != mapStudent.end(); iter++)
       {
           cout<<iter->first<<" "<<iter->second<< endl;
       }
       
       cout << "====================MAP  INSERT测试=====================
    " <<endl ;
       Insert_Pair = mapStudent.insert(pair<int, string>(2, "student_2"));
       if(Insert_Pair.second == true)
       {
              cout<<"Insert Successfully"<<endl;
       }
       else
       {
              cout<<"Insert Failure"<<endl;
       }
       Insert_Pair = mapStudent.insert(pair<int, string>(2, "student_2222"));
       if(Insert_Pair.second == true)
       {
              cout<<"Insert Successfully"<<endl;
       }
       else
       {
              cout<<"Insert Failure"<<endl;
       }
       
       for(iter = mapStudent.begin(); iter != mapStudent.end(); iter++)
       {
           cout<<iter->first<<" "<<iter->second<< endl;
       }
    }
    image 
     
  • 相关阅读:
    [转载]--python3.6 错误: ModuleNotFoundError:No module named "Crypto"
    [笔记]--RedHat6.5使用CentOS的yum源
    [笔记]--Linux公社,想要的都在里面
    [笔记]--vsftpd配置教程
    Vue 中 axios 配置使用
    Element-ui自定义主题换肤
    vue-cli项目打包需要修改的路径问题
    cookie和session 以及 localStorage和sessionStorage之间的区别和应用场景
    正则表达式
    详解-vue项目中的文件和目录
  • 原文地址:https://www.cnblogs.com/zsb517/p/3388254.html
Copyright © 2011-2022 走看看