语艺杂谈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 ...
随机推荐
- ytu 1939:统计元音(水题)
统计元音 Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 68 Solved: 33[Submit][Status][Web Board] Descrip ...
- jquery tab
jquery tab <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:// ...
- wp8 入门到精通 线程
Dispatcher.BeginInvoke(() => MessageBox.Show(String.Format("A push notification {0} error oc ...
- android 检测sqlite数据表中字段(列)是否存在 (转)
原文摘自 http://www.tuicool.com/articles/jmmMnu 一般数据库升级时,需要检测表中是否已存在相应字段(列),因为列名重复会报错.方法有很多,下面列举2种常见的方式: ...
- 调整Excel的打印线
- BZOJ 3156: 防御准备 斜率优化DP
3156: 防御准备 Description Input 第一行为一个整数N表示战线的总长度. 第二行N个整数,第i个整数表示在位置i放置守卫塔的花费Ai. Output 共一个整数,表示最小的战 ...
- [转载]有了 malloc/free 为什么还要 new/delete ?
malloc 与free 是C++/C 语言的标准库函数,new/delete 是C++的运算符.他们都可以用于申请动态内存和释放内存. 对于非内部数据类型的对象(如类对象)而言,光用m ...
- hdu 5752 Sqrt Bo
Sqrt Bo Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total S ...
- CodeForces 304C
E - E Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- Google地图接口API之申请免费API Key(一)
使用谷歌地图API V3创建交互式地图,首先需要拥有一个免费的 Google 地图 API key. 如果想调用Google地图的接口,首先需要拥有一个免费的 Google 地图 API key.想要 ...