|
|
|
|
|
|
|
Without spacing between the numbers, this output is difficult to interpret. Let's examine how we can control both the horizontal and vertical spacing of our output to make it more appealing (and understandable). We look first at vertical spacing. |
|
|
|
|
|
|
|
|
You already have seen how to control vertical spacing by using the endl manipulator in an output statement. A sequence of output statements continues to write characters across the current line until an endl terminates the line. Here are some examples: |
|
|
|
|
| Statements | Output produced | cout << "Hi there, ";
cout << "Lois Lane. " << endl;
cout << "Have you seen ";
cout << "Clark Kent?" << endl; | Hi there, Lois Lane.
Have you seen Clark Kent? | cout << "Hi there, " << endl;
cout << "Lois Lane. " << endl;
cout << "Have you seen " << endl;
cout << "Clark Kent?" << endl; | Hi there,
Lois Lane.
Have you seen
Clark Kent? | cout << "Hi there, " << endl;
cout << "Lois Lane. ";
cout << "Have you seen " << endl;
cout << "Clark Kent?" << endl; | Hi there,
Lois Lane. Have you seen
Clark Kent? |
|
|
|
|
|
|
What do you think the following statements print out? |
|
|
|
|
|
|
|
|
cout << "Hi there, " << endl;
cout << endl;
cout << "Lois Lane." << endl; |
|
|
|
|
|
|
|
|
The first output statement causes the words Hi there, to be printed; the endl causes the screen cursor to go to the next line. The next statement prints nothing but goes on to the next line. The third statement prints the words Lois Lane. and terminates the line. The resulting output is the three lines |
|
|
|
|
|