The Pre-Processor


Let's start off by talking about the C++ Pre-Processor. What is it? It's a way of telling the C++ Compiler to manipulate your program before it compiles it. For instance, say your program had grown so big that you wanted to have it split into two files. You could then tell the Pre-Processor to add one file to the beginning of the other during the compile. The compiler would see them as one big file, even though they were really two.

The way you communicate with this Pre-Processor is by using # as the first character in a line, followed by a command to send to it. Let's try using the

include
option, which adds in another file at that point:

#include "nacho"

This command adds a file named "nacho" to the program where you put this line. So, if the file you had the #include in looked like:

I want to eat
#include "nacho"
tonight!

And the file named "nacho" had in it:

some good, yummy nachos

The output the compiler would see would be:

I want to eat
some good, yummy nachos
tonight!


Table of Contents

Hello, World! | The Pre-Processor | Headers | cout: The Black Box
More Wonders of cout | cin: cout's evil twin | Exercises