码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-06-01 21:02:22      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:blog   iostream   tran   cas   find   out   nsf   transform   错误   

#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的问题(未解决)

标签:blog   iostream   tran   cas   find   out   nsf   transform   错误   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!