条件编译之宏开关

 1 #include <iostream>
 2 using namespace std;
 3 
 4 //定义一个宏开关
 5 #define __SWITCH__      
 6 
 7 
 8 int main()
 9 {
10 #ifdef __SWITCH__  
11     //如果定义了__SWITCH__开则执行下列代码段
12     cout << "SWITCH开关已打开" << endl;
13     cout << "....." << endl;
14 #else              
15     //如果为定义了__SWITCH__开则执行下列代码段
16     cout << "SWITCH开关未打开" << endl;
17     cout << "....." << endl;
18 #endif
19     system("pause");
20     return 0;
21 }

代码段为灰色则不会参与编译过程。

猜你喜欢

转载自www.cnblogs.com/main404/p/11279772.html