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 }

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

相关文章:

  • 2021-12-31
  • 2021-10-27
猜你喜欢
  • 2022-01-14
  • 2022-12-23
  • 2022-02-07
  • 2021-12-05
  • 2022-12-23
  • 2022-02-13
  • 2022-12-23
相关资源
相似解决方案