1 #include<iostream>
2 using namespace std;
3 #define AGE 18
4 #define MY_AGE 25
5 #define DISPY "已经被定义"
6 #define DISPN "尚未定义"
7 void main()
8 {
9 #ifdef AGE//判断AGE是否已被定义
10 cout<<"AGE="<<AGE<<DISPY<<endl;//如果有
11 #else
12 cout<<DISPN<<MY_AGE<<endl;//无
13 #endif
14 #undef AGE//取消AGE宏的定义
15 #ifndef AGE
16 cout<<"AGE="<<MY_AGE<<DISPN<<endl;
17 #else
18 cout<<"任何年龄却没有定义"<<endl;
19 #endif
20 system("pause");
21 }
1 #include<iostream>
2 using namespace std;
3 #define SCORE 90
4 #if SCORE>80
5 #define GRADE "表现很好"
6 #else
7 #define GRADE "尚可"
8 #endif
9 void main()
10 {
11 cout<<"你的成绩:"<<SCORE<<endl;
12 cout<<"成绩等级:"<<GRADE<<endl;
13 system("pause");
14 }
/*预处理运算符
# 字符串化运算符_将#之后的自变量以字符串显示
## 粘贴运算符_连接自变量 */
#include<iostream>
#include<string>
using namespace std;
#define ShowStr(x) #x
#define CONBINE(x,y,z) x##y##z
void main()
{
int abc=256;
cout<<"#运算符显示:"<<ShowStr(HELLO!)<<endl;
cout<<"##运算符显示:"<<CONBINE(a,b,c)<<endl;
system("pause");
}