- 2
- 0
- 约2.34万字
- 约 120页
- 2017-01-01 发布于未知
- 举报
C++程序设计(第二版) 主编 杨长兴 刘卫国 中国水利水电出版社 2.格式二 #ifndef 标识符 程序段1 #else 程序段2 #endif 或: #ifndef 标识符 程序段1 #endif 其中,ifndef、else和endif都是关键字。 3.格式三 #if 常量表达式1 程序段1 #elif 常量表达式2 程序段2 #elif 常量表达式3 程序段3 …… #else 程序段n+1 #endif 其中,if、elif和else是关键字。 当第i个常量表达式的值为真,则编译相应的“程序段i”;如果没有为真的常量表达式则编译“程序段n+1”。 【例3.24】本程序对3个输出语句作选择性编译。 //*****ex3_24.cpp***** #include iostream using namespace std; #define M 6 void main() { #if M==1 coutM值为1!endl; #elif M==2 cout M值为2!endl; #else cout M值既不是1,也不是2!endl; #endif } 本程序的运行结果如
原创力文档

文档评论(0)