< previous page page_106 next page >

Page 106
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.
Creating Blank Lines
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:
StatementsOutput 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

 
< previous page page_106 next page >