0
#include<algorithm>
#include<string>
#include<vector>
#include<functional>
#include<iostream>
using namespace std;
class WordCompare:binary_function<string,string,bool>
{
public:
	bool operator()(const string&a ,const string& b)
	{
		if(a.at(0)==b.at(0))
			return true;
		else 
			return false;
	}
};
int main()
{
	vector<string>MainText;
	vector<string>TempString;
	vector<string>::iterator i;
	MainText.push_back("All");
	MainText.push_back("art");
	MainText.push_back("is");
	MainText.push_back("quite");
	MainText.push_back("useless");
	TempString.push_back("quite");
	TempString.push_back("unique");
	i=search (MainText.begin(),MainText.end(),TempString.begin(),
		TempString.end(),WordCompare());
		if(i==MainText.end())
			cout<<"The substring is not found"<<endl;
		else
			cout<<"The substring is found"<<endl;
		return 0;
}

why there should have a class definition?
is that the definition style of any function object?

2
Contributors
1
Reply
2
Views
12 Years
Discussion Span
Last Post by Stoned_coder
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.