< Previous | Contents | Next >

Including Other Files

The next line in the program is a preprocessor directive. You know this because the line begins with the # symbol.

#include <iostream>

The preprocessor runs before the compiler does its thing and substitutes text based on various directives. In this case, the line involves the #include directive, which tells the preprocessor to include the contents of another file.

8 Chapter 1 n Types, Variables, and Standard I/O: Lost Fortune


I include the file iostream, which is part of the standard library, because it contains code to help me display output. I surround the filename with less than (<) and greater than (>) characters to tell the compiler to find the file where it keeps all the files that came with the compiler. A file that you include in your programs like this is called a header file.