1. 什么是预处理指令
以#
开头为标识,后接指令关键字
的一行语句。在编译前对代码转换。
2. 指令关键字
include
define
定义宏。
注意参数要括起来:
#define SQE(x) (x*x) // wrong
#define SQE(X) ((x)*(x)) // correct
条件编译指令
决定哪些代码被编译,哪些不被编译。
# define DEBUG
test()
{
# ifdef DEBUG //判断是否定义了DEBUG
cout<<"yes"<<endl;
# elif DEBUG2
cout<<"yes"<<endl;
# endif
# ifndef DEBUG
cout<<"no"<<endl;
# endif
}