How about if you create a function that takes a large string (i.e. the user inputted sentence string named "line") and returns a vector of smaller strings? Each string in the vector would be a word. Something like this:
vector <string> ParseIntoWords (string sentence);
So in your example, you pass this function the string "I hate programming" and it returns a vector of three strings:
I
hate
programming
The function you have could help parse out the separate words, as could the function "isspace" from the cctype library: http://www.cplusplus.com/reference/clibrary/cctype/isspace.html
Also potentially useful could be this function:
http://www.cplusplus.com/reference/string/string/substr.html
You could then go through this vector of strings and check to see whether a string had four letters. If so, change the string. You end up with a vector like this:
I
love
programming
Concatenate the above vector of strings and you have your revised string (except from the period. Also you may have to put the spaces back in).