map初始化 智能指针 c11语法


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string.h> 
#include <stdio.h>
#include <vector>
#include<map>
using namespace std;

int main()
{
	int arr[3]{1,2,3};
	vector<int> iv {1,2,3};
	map<string,int>  mp;
	
	mp.insert({ "abc", 1 });    //使用这种就可以了
    //其他形式和方式
	mp.insert(make_pair(string("def"),2));
	mp.insert(make_pair("ghj", 4));
	mp.insert(pair<string, int>(string("kmn"), 3));
	mp[string("pqrs")] = 5;
	
	pair<map<string,int >::iterator,bool>  ret = mp.insert(map<string, int >::value_type("ghj",3333));
	if(ret.second){
		cout<<"insert success"<<endl;
		cout<<"ret->first->first :"<<ret.first->first <<endl;
		cout<<"ret->first->second :"<<ret.first->second <<endl;
		
	} else{
		cout<<"insert fail"<<endl;
	}
	
	//pair<map<int,string>::iterator,bool> ret1 = mp.insert(map<int, string>::value_type(22,"twotwo"));
	
	//mp
	for(auto i= mp.begin(); i!= mp.end();i++)
	{
		cout<< i->first<< " "<< i->second<< endl;
	}
	
	//pair<map<string,int >::iterator,bool> ret
	for(auto & s:mp)
	{
		cout<< s.first<< " "<< s.second<< endl;
	}
	return 0;
}

map初始化

https://blog.csdn.net/Leo_csdn_/article/details/86589904


	mp.insert(make_pair("ghj", 4));
	mp.insert(pair<string, int>(string("kmn"), 3));
    mp.insert(map<string, int >::value_type("ghj",3333));
	mp[string("pqrs")] = 5;

insert返回

pair<map<int,int>::iterator,bool> ret=map.insert(make_pair(...));
if(!ret.second)
//插入失败

c11新语法

统一初始化

auto类型自动推导

for循环 foreach便利

智能指针 shared_ptr

。。。

https://www.jianshu.com/p/d0a98e0eb1a8

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值