Hello I'm trying to right a program that reverses the order or words in strings.
The thing is I don't know how to do this. I only know how to reverse each letter using strrev() and the for loop method like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
int main ()
cout << "Enter a string: ";
int sizestr = strlen(str);
cout << str[sizestr];
But I'm required to reverse the word order something like
A first step might be to identify each individual word in the string. There are many ways to do this, though a stringstream might be the simplest. Then generate a new string by inserting each word (and a separating space if necessary) at the beginning of the new string. http://www.cplusplus.com/reference/string/string/insert/
Or store all the individual words in an array or vector and loop in reverse through the stored words to build the new string.