cpp implementation for reverse words in a string