... The first stream insertion (line 7) prints Welcome followed by a space, and because this string did not end with \n, the second stream insertion (line 8) begins printing on the same line immediately following the space.

Fig. 2.3 Printing a line of text with multiple statements.

Alternate View

 1   // Fig. 2.3: fig02_03.cpp
 2   // Printing a line of text with multiple statements.
 3   #include <iostream> // enables program to output data to the screen
 4
 5   // function main begins program execution
 6   int main() {
 7      std::cout << "Welcome ";
 8      std::cout << "to C++!\n";
 9   } // end function main 

Welcome to C++!

Printing Multiple Lines of Text with a ...

Get C++ How to Program, 10/e now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.