语艺杂谈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 赋值测试=====================\n" <<endl ;
map<int, string>::iterator iter;
for(iter = mapStudent.begin(); iter != mapStudent.end(); iter++)
{
cout<<iter->first<<" "<<iter->second<< endl;
} cout << "====================MAP INSERT测试=====================\n" <<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;
}
}
语艺杂谈1 – MAP赋值与插入的更多相关文章
- go语言基础之map赋值、遍历、删除 、做函数参数
1.map赋值 示例: package main //必须有个main包 import "fmt" func main() { m1 := map[int]string{1: &q ...
- map容器对象插入数据的4种方式
#include <string> #include <iostream> #include <map> #include <utility> u ...
- map赋值前要先初始化:assignment to entry in nil map
注意这种map的嵌套的形式,make只初始化了map[string]T部分(T为map[int]int),所以下面的赋值会出现错误: test := make(map[string]map[int]i ...
- map两种插入方法解析(insert() 与 下标[]操作)
insert 含义是: 如果key存在,则插入失败,如果key不存在,就创建这个key-value. 实例: map.insert((key, value)) 利用下标操作的含义是: 如果这个key存 ...
- GO语言中json与map的转换
直接上代码(需要引入encoding/json包) // 当前程序的包名 package main // 导入其它的包 import ( "encoding/json" " ...
- c++ map和mutimaps 插入值
(1)运用value_type std::map<std::string, float> col1; col1.insert(std::map<std::string,float&g ...
- Golang 嵌套map赋值办法
http://my.oschina.net/sol/blog/159060 m := map[string]map[string]string{} mm, ok := m["kkk" ...
- C++ 关联容器之map插入相同键元素与查找元素操作
一.插入相同键元素操作 (1)insert方法 在map中的键必须是唯一的,当想map中连续插入键相同但值不同的元素时,编译和运行时都不会发生任何错误,系统会忽略后面的对已存在的键的插入操作,如 ma ...
- Golang Map实现(四) map 的赋值和扩容
title: Golang Map 实现 (四) date: 2020-04-28 18:20:30 tags: golang map 操作,是map 实现中较复杂的逻辑.因为当赋值时,为了减少has ...
随机推荐
- DB2修改表字段
1:删除字段非空属性 alter table XXX alter column XXX drop not null 此特性需要DB2 9.0以上的版本 2:添加字段非空属性alter table XX ...
- burpsuite绕过本地javascripte上传文件
burpsuite绕过本地javascripte上传文件 先是找到图片上传的位置: 上传个asp文件试试,一点击上传就出现: 这样基本就可以确定是本地检测文件后缀名的方式来 ...
- ModifyInfo.aspx.cs代码
涉及修改密码,提交请求 操作,修改数据库内容 using System; using System.Collections.Generic; using System.Linq; using Syst ...
- mvc-3模型和数据(1)
MVC和命名空间 var User = function(atts) { this.attribute = atts || {}; } //和具体user相关的方法 User.prototype.de ...
- json学习系列(4)-JSONString对象的optXXX方法的使用
在JSONObject获取value有多种方法,如果使用 getXxx()类型的方法获取value,如getString("key").如果key不存在的话,这些方法无一例外的都会 ...
- ZOJ1654 Place the Robots(二分图最大匹配)
最大匹配也叫最大边独立集,就是无向图中能取出两两不相邻的边的最大集合. 二分图最大匹配可以用最大流来解. 如果题目没有墙,那就是一道经典的二分图最大匹配问题: 把地图上的行和列分别作为点的X部和Y部, ...
- 亲和数[HDU2040]
亲和数 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- wp ApplicationBar
WP7中的菜单栏 一个应用程序的菜单栏的内容是有限的,最多不超过4个,排列顺序是以菜单栏中间为中心,然后从左往右排列. WP7提供了两种类型的菜单栏,一种是全局的菜单栏,也就是说在所有的页面中都会出现 ...
- JSON.stringify语法解析(自己留存)
语法: JSON.stringify(value [, replacer] [, space]) value:是必选字段.就是你输入的对象,比如数组,类等. replacer:这个是可选的.它又分为2 ...
- linux用户和组管理
添加组groupadd sftp 把用户mysftp加入组sftp中:gpasswd -a mysftp sftp 把用户mysftp加入组sftp中:usermod -a -G sftp mysft ...