二元谓词的重载2
2016-03-22 20:28
246 查看
#include <iostream> #include <set> #include <string> #include <algorithm> using namespace std; class CCompareStringNoCase // 这是一个不分大小写的二元谓词的类, { public: bool operator() (const string& str1,const string& str2) const { string str1LowerCase; str1LowerCase.resize(str1.size()); transform(str1.begin(),str1.end(),str1LowerCase.begin(),tolower); string str2LowerCase; str2LowerCase.resize(str2.size()); transform(str2.begin(),str2.end(),str2LowerCase.begin(),tolower); return (str1LowerCase<str2LowerCase); } }; int main() { // 二元谓词 set<string,CCompareStringNoCase> names; names.insert("xiao"); names.insert("Xiao"); names.insert("xIao"); names.insert("cui"); set<string,CCompareStringNoCase>::iterator iNameFound = names.find("Cui"); if(iNameFound != names.end()) { cout << "找到了," << *iNameFound << endl; } else { cout << "没有找到了," << endl; } return 0; }
相关文章推荐
- 从linux启动到rootfs的挂载分析
- 据廖雪峰python3教程----python学习第五天
- 第二周项目4:穷举法解决组合问题(3)
- Linux下Caffe初学测试笔记
- 利用github page搭建博客
- nginx配置ssl加密(单/双向认证、部分https)
- hdu 1358 Period
- 是否需要有代码规范?
- 规范制度是否都是有意义?
- Jedis源码解析(ShardedJedis)
- HDU 2123 An easy problem
- CF IndiaHack B 深度优先搜索
- 用shell简单处理文本的例子
- 安卓中onBackPressed ()方法的使用
- LightOj 1231 Coin Change (I)(部分背包)
- Raspberry PI3(树莓派)第一课:Tomcat+pi4j远程控制led
- 夜课后的明月
- 第四周项目3-随机数应用于游戏
- 贪心算法1之1016
- 安卓开发常见错误原因及解决方法