You may want to read the documentation for string.find() and perhaps use the return value from that function. Then, to continue your thought, you may want to consider reading the documentation for the std::string class to see if there isn't a member function that "rings a bell".
If you would have used code tags in your post you may have been able to see that:
1 2 3 4 5 6 7 8 9 10
string replace_sentence(string s)
{
s = string(s.begin(), s.end());
if (s.find("hate") != std::string::npos)
{
///replace "hate" with "love"
}
}
there is the challenge that replace the word with if statement
That's why I suggested you find and read the documentation for that standard class. That class has quite a few member functions that may do just what you want.