#ifdef乃条件编译
运行结果为:
Press any key to continue
运行结果为:
Beginning execution of main()
Press any key to continue
使用#ifdef指示符,我们可以区隔一些与特定头文件、程序库和其他文件版本有关的代码。
1、代码举例:新建define.cpp文件
#include "iostream.h"
int main()
{
#ifdef DEBUG
cout<< "Beginning execution of main()";
#endif
return 0;
}
运行结果为:
Press any key to continue
2、改写代码如下:
#include "iostream.h"
#define DEBUG
int main()
{
#ifdef DEBUG
cout<< "Beginning execution of main()";
#endif
return 0;
}
运行结果为:
Beginning execution of main()
Press any key to continue