#ifdef 宏名
程序段1;
#else
程序段2;
#endif
功能:如果宏名已被定义,则编译程序段1,否则编译程序段2.
例子
#include <bits/stdc++.h>
using namespace std;
#define A //此时#ifdef A 为真
int main()
{
#ifdef A
cout<<1;
#else
cout<<2;
#endif
return 0;
}
输出:
1
#ifdef 宏名
程序段1;
#else
程序段2;
#endif
功能:如果宏名已被定义,则编译程序段1,否则编译程序段2.
例子
#include <bits/stdc++.h>
using namespace std;
#define A //此时#ifdef A 为真
int main()
{
#ifdef A
cout<<1;
#else
cout<<2;
#endif
return 0;
}
输出:
1