#include #include "CPstring.h" // file: reverse.cc // author Dietolf Ramm; date: 11/13/96 // Function to revers order of characters in a string // Illustrate addressing of characters in string by subscripts const int ROWS = 25; const int COLS = 50; const char PCHAR = '*'; void ReverseChar(string & str) // postcondition: characters with the string str have been reversed in // order { int k, lng = str.length(); char c; for (k = 0; k < lng/2; k++) { c = str[k]; str[k] = str[lng - k - 1]; } } int main() { string s; cout << "Enter string (enter to quit)" << endl; getline(cin, s); while (s.length() > 0) { ReverseChar(s); cout << "result is: " << s << endl; cout << "Enter string (enter to quit)" << endl; getline(cin, s); } return 0; } Sample output: reverse Enter string (enter to quit) Hello result is: olleH Enter string (enter to quit) morgan result is: nagrom Enter string (enter to quit) It was the best of times. result is: .semit fo tseb eht saw tI Enter string (enter to quit)