C9 Lectures: Stephan T. Lavavej - Standard Template Library (STL) 2笔记


#include <functional>//c++11
#include<algorithm>//包括,remove and erase
#include<iostream>
#include<map>
#include <ostream>
#include<unordered_map>
#include <string>
#include <vector>
using namespace std;
/*-----------------------
map的基本使用
int main(){
	map<int,string> m;
	m[1]="one";
	m[2]="two";
	m[4]="four";
	m[3]="three";
	m[2]="TWO!";
	//cout<<m[2]<<endl;//right:
	for (auto i=m.begin();i!=m.end();++i)
	{
		cout<<i->first<<" "<<i->second<<endl;
	}
	m.clear();
}
-------------------------------*/


/*------------------------------------------
map在函数中的调用相关,不明问题1
void foo(const map<int,string> &m){
	//m[7]="seven";//false;m is const
	cout<<m[3]<<endl;//                                               wrong:DONT KNOW !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	map<int,string>::const_iterator i=m.find(3);
	if (i==m.end())
	{
		cout<<"Not Found"<<endl;
	} 
	else
	{
		cout<<i->second<<endl;
	}
}

int main(){
	map<int,string> m;
	m[1]="one";
	m[2]="two";
	m[4]="four";
	m[3]="three";
	m[2]="TWO!";
	//cout<<m[2]<<endl;//right:
	foo(m);
	for (auto i=m.begin();i!=m.end();++i)
	{
		cout<<i->first<<" "<<i->second<<endl;
	}
	m.clear();
}
---------------------------------------*/

/*--------------------------------------
boost库中的map ,按照hash_value判断,问题1,什么是hash_value
int main(){
	unordered_map<int,string> m;
	m[1]="one";
	m[2]="two";
	m[4]="four";
	m[3]="three";
	m[2]="TWO!";
	//cout<<m[2]<<endl;//right:
	for (auto i=m.begin();i!=m.end();++i)
	{
		cout<<i->first<<" "<<i->second<<endl;
	}
	m.clear();
}
-------------------------*/

/*----------------------------
c++11 包含 functional头文件后的使用,以后补充
int main(){
	map<int,string,greater<int>> m;
	m[1]="one";
	m[2]="two";
	m[4]="four";
	m[3]="three";
	m[2]="TWO!";
	//cout<<m[2]<<endl;//right:
	for (auto i=m.begin();i!=m.end();++i)
	{
		cout<<i->first<<" "<<i->second<<endl;
	}
	m.clear();
}
-------------------------------*/

/*-----------------------------
使用functional 和 algorithm,对函数内容进行删减
int main()
{
	vector<int> v;
	v.push_back(11);
	v.push_back(22);
	v.push_back(33);
	v.push_back(44);
	v.push_back(55);
	v.erase(remove_if(v.begin(),v.end(),[](int e){return e%2==1;}),v.end());
	for (auto i=v.begin();i!=v.end();++i)
	{
		cout<<*i<<endl;
	}
	v.clear();
}
--------------------------------------*/

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值