Printing Multiple Lines of Text with a Single Statement

A single statement can print multiple lines by using newline characters, as in line 8 of Fig. 2.4. Each time the (newline) escape sequence is encountered in the output stream, the screen cursor is positioned to the beginning of the next line. To get a blank line in your output, place two newline characters back to back, as in line 8.


 1   // Fig. 2.4: fig02_04.cpp
 2   // Printing multiple lines of text with a single statement.
 3   #include <iostream> // allows program to output data to the screen
 4
 5   // function main begins program execution
 6   int main()
 7   {
 8      std::cout << "Welcome to C++! ";
 9   } // end function main


Welcome
to

C++!


Fig. 2.4. Printing multiple lines of text with a single statement.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset