自定义map比较规则及函数调用
来源:互联网 发布:上海电脑数据恢复 编辑:程序博客网 时间:2024/06/04 19:38
参考文章:http://blog.csdn.net/challenge_c_plusplus/article/details/7429963
注意:
1、比较函数中形参为常量引用, 即const string & 形式。
2、typedef bool (*comp)(const string &,const string &);
3、定义:map<string, int, comp> my_map(my_compare);
3、函数形参:map<string, int, comp> my_map,即不用标明什么比较规则,给出类型即可。
#include <iostream>#include <utility>#include <string>#include <map>using namespace std;bool my_compare(const string &str1, const string &str2){return str1 > str2;}typedef bool (*comp)(const string &,const string &);void test(map<string, int, comp> my_map) { cout << my_map.size() << endl; map<string, int,comp>::const_iterator itr = my_map.begin();while ( itr != my_map.end()) {cout << itr->first << " : " << itr->second << endl;itr++;}}int main(int argc, char *argv[]){map<string, int, comp> my_map(my_compare);my_map["wjj"] = 1;my_map["lqm"] = 2;my_map["mei"] = 3;test(my_map);return 0;}
0 0
- 自定义map比较规则及函数调用
- map及set中自定义比较函数
- map自定义比较函数
- map自定义比较函数
- map自定义比较函数
- map自定义比较函数
- map中自定义比较函数
- stl中map自定义比较函数
- [C/C++]map自定义比较函数
- [C/C++]map自定义比较函数
- stl中map自定义比较函数
- map和set容器自定义比较函数
- JavaScript函数使用及调用规则
- 自定义规则比较器
- 自定义结构作为map的key,比较函数写法
- STL中sort、priority_queue、map、set的自定义比较函数
- STL中sort、priority_queue、map、set的自定义比较函数
- 自定义结构作为map的key,比较函数写法
- 驱动模块(ko)文件加载失败分析
- android颜色对应的xml配置值
- 电脑花屏不一定是显卡问题
- Linux 下 Hadoop 安装准则
- QString 类的使用
- 自定义map比较规则及函数调用
- 文件上传之路
- Swift中文教程(十一) 方法
- MSP430学习笔记:UART
- powerdesigner导出表到word,不是正常的表格格式
- 【性能观察室】 android Trace view 工具使用
- 控制台的二叉树树形显示
- java的大数据
- Android电源管理