首页 > 其他 > 详细

二元谓词中添加const的问题(未解决)

时间:2017-06-01 20:49:12      阅读:343      评论:0      收藏:0      [点我收藏+]
#include  <iostream>
using namespace std;
#include"set"
#include"algorithm"
struct compareNoCase
{

	//bool operator()(const string &str1, const string &str2)  这种居然是错误的。不知道为什么
	bool operator()(const string &str1, const string &str2) const
	{
		string str11;
		str11.resize( str1.size ());
		transform(str1.begin(), str1.end(), str11.begin(), tolower);
		string str22;
		str22.resize ( str2.size());
		transform(str2.begin(), str2.end(), str22.begin(), tolower);
		return (str11 > str22);
	}
};
void main01()
{
	set<string > s1;
	s1.insert("aaa");
	s1.insert("wew");
	s1.insert("qwe");

	set<string>::iterator it = s1.find("aaa");
	if (it == s1.end())
	{
		cout << "没有找到" << endl;
	}
	else
		cout << "找到" << endl;
	set<string, compareNoCase> s2;
	s2.insert("aAa");
	s2.insert("wSw");
	s2.insert("qAe");

	set<string, compareNoCase>::iterator it2 = s2.find("aAa");
	if (it2 == s2.end())
	{
		cout << "没有找到" << endl;
	}
	else
		cout << "找到" << endl;

}
int main()
{
	main01();
	system("pause");

}

  

二元谓词中添加const的问题(未解决)

原文:http://www.cnblogs.com/xiaochige/p/6930670.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!