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 
     
  • 相关阅读:
    python 发包爬取中国移动充值页面---可判断手机号是否异常
    python利用selenium和safari浏览器驱动实现新浪微博自动点赞 Demo
    Django学习报错记录
    nginx和tomcat的区别
    Mac主机映射到域名
    mac下eclipse安装svn插件-subclipse
    移动端——等分,居中
    移动端——重置样式
    M端页面-绝对定位布局
    jquery-练习-折叠效果
  • 原文地址:https://www.cnblogs.com/zsb517/p/3388254.html
Copyright © 2011-2022 走看看