#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();
}
--------------------------------------*/