The Parts of a Simple Program

The simple program from the first hour, HELLO.CPP, had many interesting parts. This section will review this program in more detail. Listing 2.1 reproduces the original version of HELLO.CPP for your convenience.

Listing 2.1. HELLO.CPP Demonstrates the Parts of a C++ Program
0:  #include <iostream>
1:
2:  int main()
3:  {
4:      std::cout << "Hello World!\n";
5:      return 0;
6:  }
Hello World!

On line 0 the file iostream is included in the file. As far as the compiler is concerned, it is as if you typed the entire contents of the file iostream right into the top of HELLO.CPP.

Examining the #include, Character by Character ...

Get Sams Teach Yourself C++ in 24 Hours, Third Edition 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.