2.2 First Program in C++: Printing a Line of Text

Consider a simple program that prints a line of text (Fig. 2.1). This program illustrates several important features of the C++ language. The text in lines 1–10 is the program’s source code (or code). The line numbers are not part of the source code.

Fig. 2.1 Text-printing program.

Alternate View

 1    // Fig. 2.1: fig02_01.cpp
 2    // Text-printing program.
 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 to C++!\n"; // display message
 8
 9       return 0; // indicate that program ended successfully ...

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.