1: // Filename: REVLINE1.CPP
2: // Purpose: Reads in a line of input and then writes out
3: // the line with all characters in reverse order.
5: #include <iostream>
6: using namespace std;
8: void ReadRestOfCharsAndWriteInReverse();
10: int main()
11: {
12: cout << endl;
14: cout << "This program reads a sentence and "
15: << "then writes it out in reverse order." << endl;
16: cout << endl;
18: cout << "Enter a sentence on the following line: " << endl;
19: ReadRestOfCharsAndWriteInReverse();
21: cout << endl << endl;
23: return 0;
24: }
27: void ReadRestOfCharsAndWriteInReverse()
28: // Pre: The standard input stream is empty.
29: // Post: All characters entered by the user, up to the
30: // first newline character, have been read in and
31: // written out in reverse order.
32: {
33: char ch;
35: cin.get(ch);
36: if (ch == '\n')
37: ; // Stop (i.e., do nothing, since you're finished).
38: else
39: {
40: ReadRestOfCharsAndWriteInReverse();
41: cout << ch;
42: }
43: }