Reverse letter in each word

February 12, 2011 at 14:24:24
Specs: Windows XP
I have to write a C++ function that will accept a std::string and reverse the letters in each word. For example: "My name is Charlie" should output "yM eman si eilrahC

My function reverses the entire string:

int main()
std::string s;
printf("Please enter a line: \n\n");
std::cout << "Input: ";
std::getline(std::cin, s);
std::reverse(s.begin(), s.end());
std::cout << "Output: ";
std::cout << s << std::endl;
std::cout << "\n";

return 0;

Any help would be appreciated. Thanks!!!!

See More: Reverse letter in each word

Report •

February 12, 2011 at 21:40:43
You have to parse your string into words and reverse each word. Assume the delimiter is a space.

Report •

February 13, 2011 at 05:06:04
I'd suggest creating a function that takes an int x and looks up the x space in the string, then loop that with your function and append to a temp string every loop.

Live the life as you know it
/ Wille

Report •

February 13, 2011 at 19:42:10
It worked.....Thanks a million!!!!

Report •

Related Solutions

Ask Question