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 line numbers are not part of the source code.

 1   // Fig. 2.1: fig02_01.cpp 2   // Text-printing program. 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++!\n"; // display message 9 10      return 0; // indicate that program ended successfully11   } // end function main

Welcome to C++!

Fig. 2.1. Text-printing program.

Get C++11 for Programmers, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.