Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

detect a word in string using getline()

Status
Not open for further replies.

miketm

Programmer
Joined
Oct 19, 2003
Messages
18
Location
AU
Hi everyone,

Please give me some good idea how to detect a partcular word (say "you") in a string when you read in using getline. I only know how to detect a word from a constant string by using strstr(), and find() for a single character matching. But strstr() does not allow you to detect a word from a line you read from a file. Any ideas will be greatly appreciated. Thanks

Miketm
 
If you mean "find" some substring in a string, you can use string::find, there is an overloaded version of this feature for string searches.

From STL :

Code:
size_type find(const string& s, size_type pos = 0) const

doc:
Searches for s as a substring of *this, beginning at character pos of *this.



--
Globos
 
Thank you Globos, yes I meant "find" some substring in a string . This afternoon at work I experimented out many other methods and eventually I also managed to use find() correctly, that is using the pos outcome of find(). I misused before, lol ,that made me crazy testing & testing.

Thanks again.
Miketm
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top