Hi, I am wondering how to search through a text file for one specific word and display what is after it. For example, search for the word Rice: and display just the price.
We could explain this one as well while we're at it. As the first parameter "strstr()" requires a const char pointer, conveniently enough this is what the std::string.c_str() member function returns. The second parameter is a constant pointer to the string you are looking for. So in MiiNiPaa's code the only differences would be the inclusion of the cstring header and Line 5 which would be changed to:
if(strstr(name.c_str(), "Rice") != NULL)
That wasn't so bad was it? But really there is no reason to go including another header when you could just use std::string.compare() which looks like this:
if(name.compare("Rice") == 0)
Then again, since the position of the buffer matters here I almost want to say that std::string.find() is the best candidate. Oh well, dealers choice I guess.