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 
     
  • 相关阅读:
    [LeetCode#260]Single Number III
    1 sql server中添加链接服务器
    1 sql server 中cursor的简介
    1 .net将xml反序列化
    1 C# 将对象序列化
    1 SQL SERVER 实现字符串分割成table的方法
    1 asp.net 中如何把用户控件应用于母版页
    1 .net中自定义事件的步骤
    .NET中跨线程访问winform控件的方法
    1 sql server 中merge的用法
  • 原文地址:https://www.cnblogs.com/zsb517/p/3388254.html
Copyright © 2011-2022 走看看