The pre-processing functions provided by C ++ include macro definition, file inclusion, and Conditional compilation. They are implemented by macro definition commands, file inclusion commands, and Conditional compilation commands.
Preprocessing command
Format: # preprocessing command ...... (No credit points at the end)
Scope: from the definition pointProgramEnd
Description: The pre-processing command occupies only one row and has any location.
Macro definition command
Format: # define macro name [(parameter)] macro
# UNDEF macro name [(parameter)]
Scope: from the definition point to # UNDEF; otherwise, the entire file ends.
Description: The macro name can be an identifier without parameters or an identifier with parameters;
A macro can be any character sequence, but also an expression or multiple statements;
The keyword UNDEF is used to cancel the definition of the identifier. The canceled identifier can be used as another identifier;
The parameter is not a variable. It is just a symbol and has no type identifier;
Macro expansion is just a mechanical replacement.
Example:
# Define PI 3.1415
# Define s (r) pI * r // defines the macro S (R), and calculates the area of the circle whose radius is R.
File Inclusion command
Format: # include <File Name> or # include "file name"
Note: Angle brackets indicate that the included files are retrieved based on the system standard library path;
Double quotation marks indicate that the file to be included is first searched for in the file directory where the source file to be referenced is included. If the file cannot be found, the file to be included will be searched according to the standard library path of the system.
Include, or search for included files by path specified in double quotation marks. If no path is specified, search for included files in the current directory;
There are two types of files: header file (. h) and source file (. cpp );
Use <> for system files and "" for user-defined files "".
Conditional compilation command
Format: # If ...... # Endif
# If ...... # Else ...... # Endif
# If ...... # Elif ...... # Elif ...... # Else ...... # Endif
# Ifdef ...... # Else ...... # Endif
# Ifndef ...... # Else ...... # Endif
Note: Using Conditional compilation can avoid repeatedly containing a header file in a program.