1. // echoFor.cpp
2. // Echoes lines of text typed by the user,
3. // until the user types Ctrl-C to quit.
4. //
5. // Run this program and understand how it works.
6. // Then re-write as equivalent nested while loops.
7. //
8. // In the heading of the inner loop,
9. // '\n' is the newline character, used as
10. // end-of-line marker on Unix systems.
11. // (On Windows systems, the end-of-line
12. // marker would consist of a carriage
13. // return, '\r', followed by newline.)
14.
15. #include <iostream>
16. using namespace std;
17.
18. int main()
19. {
20.
21. cout << "Type a few lines of text, "
22. << "then Ctrl-C to quit:" << endl;
23.
24. char letter;
25. for ( cin.get(letter) ; ; cin.get(letter) )
26. {
27. cout << "You tuped: ";
28.
29. for ( ; letter != '\n'; cin.get(letter) )
30. cout << letter;
31.
32. cout << endl;
33. cout << "Type another line (or Ctrl-C to quit):" << endl;
34. } // for
35. } // function main