#include "iostream.h"
int main()
{
#ifdef DEBUG
cout<< "Beginning execution of main()";
#endif
return 0;
}
运行结果为:Press any key to continue
改写代码如下:
#include "iostream.h"
#define DEBUG
int main()
{
#ifdef DEBUG
cout<< "Beginning execution of main()";
#endif
return 0;
}
运行结果为:Beginning execution of main()
更一般的情况是,#define语句是包含在一个特定的头文件中。
比如,新建头文件head.h,在文件中加入代码:
#ifndef DEBUG
#define DEBUG
#endif
而在define.cpp源文件中,代码修改如下:
#include "iostream.h"
#include "head.h"
#ifdef DEBUG
cout<< "Beginning execution of main()";
#endif
return 0;
}
运行结果如下:Beginning execution of main()
联系客服