#pragma warning (disable:4786)
#include<iostream>
#include<cstring>
#include<map>
using namespace std;
struct Info
{
string name;
float score;
bool operator< (const Info &a) const
{
return a.score<score;
}
};
int main(int argc, char* argvp[])
{
map<char,char> m;
for(int j=0;j<10;j++)
{
m['0'+j]=j+'h';
}
map<char,char>::iterator it;
for(it=m.begin();it!=m.end();it++)
{
cout<<(*it).first<<' '<<(*it).second<<endl;
}
cout<<endl;
map<Info,int> m1;
Info info;
info.name="Jack";
info.score=60;
m1[info]=25;
info.name="Peter";
info.score=80;
m1[info]=15;
info.name="Marry";
info.score=100;
m1[info]=34;
map<Info,int>::iterator itm;
for(itm=m1.begin();itm!=m1.end();itm++)
{
cout<<(*itm).second<<':'<<((*itm).first).name<<' '<<((*itm).first).score<<endl;
}
multimap<string,double> m2;
m2.insert(pair<string,double>("Jack",30.3));
m2.insert(pair<string,double>("Aity",123.2));
m2.insert(pair<string,double>("Mike",34.5));
m2.insert(pair<string,double>("Jack",344.1));
multimap<string,double>::iterator itm2;
for(itm2=m2.begin();itm2!=m2.end();itm2++)
cout<<(*itm2).first<<' '<<(*itm2).second<<endl;
return 0;
}
STL--map
最新推荐文章于 2023-04-29 16:15:03 发布