+1  A: 

As to the 2nd point: string class does have a method find, see http://www.cppreference.com/wiki/string/find

Piotr Kalinowski
Thanks Piotr, I'm using string::find method. However, problem is, I want to be able to search keyword/phrases with punctutions as well. Right now I am doing following, but there must be a better way: vector<string> ext; ext.push_back((" "+keyword+" ")); ext.push_back((" "+keyword+", ")); ext.push_back((" "+keyword+". ")); ext.push_back((" "+keyword+".")); ..... ..... for(vector<string>::const_iterator it=ext.begin(); it!=ext.end(); ++it){ if(text.find(*it) != string::npos) return true; } return fasle;
Azeem Michael
You need only to do text.find(keyword) — find searches for *string* (as in sequence of characters, not just word) and is oblivious to what is adjacent to any occurrence of that string, be it punctuation or anything else.
Piotr Kalinowski
The problems with this approach is if I have a text = "this is a test". text.find("hi") will return 1 eventhout I am searching for "hi" not any occurance of "hi" within text. Find looks for any string match within the text and thus fails to find exact keywords/phrases within text.
Azeem Michael
Searching for "hi" is misleading the way you understand it. You want to search for word "hi", instead of subsequence. If you want to use word boundaries, you will need to use regular expressions, like in other answers here.
Piotr Kalinowski
+1  A: 

TR1 has a regex class (derived from Boost::regex). It's not quite like you've used above, but reasonably close. Boost::phoenix and Boost::Spirit also provide similar capabilities, but for a first attempt the Boost/TR1 regex class is probably a better choice.

Jerry Coffin
A: 

Sure there is, try Spirit:

http://boost-spirit.com/home/

Quonux