Examples
#include <iostream.h> #include "myheader.h" #ifdef MINE
#define filename "file1.h" #else
#define filename "file2.h" #endif
#include filename
The #include_next preprocessor directive is similar to the #include directive, but tells the preprocessor to continue the
Macro Replacement (#define, #undef)
You can define C++ macros to substitute text in your source file.
Syntax
#define identifier
#define identifier(
Description
A#define preprocessing directive defines the identifier as a macro name that represents the
#define identifier
The macro name is then replaced by the list of tokens wherever it appears in the source file (except inside of a string, character constant, or comment). A macro definition remains in force until it is undefined through the use of the #undef directive or until the end of the compilation unit.
The
#define mac very very long\
replacement string
The \ must be the last character on the line. You cannot add any spaces or comments after it.
Macros can be redefined without an intervening #undef directive. Any parameter used must agree in number and spelling with the original definition, and the replacement lists must be identical. All white space within the
#define foo x + y
#define foo x + y
The
Macros with Parameters
You can create macros that have parameters. The syntax of the #define directive that includes formal parameters is as follows:
Overview of the Preprocessor 121