// constructing maps
#include <iostream>
#include <map>
using namespace std;
bool fncomp (char lhs, char rhs) {return lhs<rhs;}
struct classcomp {
bool operator() (const char& lhs, const char& rhs) const
{return lhs<rhs;}
};
void print(map<char,int>& mymap)
{
map<char,int>::iterator myit = mymap.begin();
for(;myit!=mymap.end();myit++)
{
cout << myit->first <<"\t"<< myit->second << endl;
}
}
int main ()
{
map<char,int> first;
first['a']=10;
first['b']=30;
first['c']=50;
first['d']=70;
print(first);
map<char,int> second (first.begin(),first.end());
print(second);
map<char,int> third (second);
print(third);
map<char,int,classcomp> fourth; // class as Compare
bool(*fn_pt)(char,char) = fncomp;
map<char,int,bool(*)(char,char)> fifth (fn_pt); // function pointer as Compare
return 0;
}
map
最新推荐文章于 2022-05-17 16:27:43 发布