Monday, May 24, 2010

C++ codehow to input data into string like from file and than search for particular word in the string.?Thanks

if U have a file called f.txt for example U can make th following





freopen("f.txt","rt",stdin);





string s = "";





getline(cin,s); // this will read a line from the file





//now to search for a word use





s.strstr("Ur word"); // will return -1 in case the string is not found and the index of the start of the word otherwise





Regards,

strawberry

No comments:

Post a Comment