c++预处理命令

c++预处理器提供了预处理命令

#define 宏定义

#undef 取消宏定义

#else #elif #endif #error

#if, #ifdef.......

这些命令在编译之前完成

#define pi 3.1425926

#define Min(a,b)  ((a) < (b)?(a):(b))



#undef取消宏定义

#undef Min 之后这个Min就没有意义了

  条件编译

#ifdef 标识符
  语句组1
[#else
  语句组2 
] 
#endif
[]可选部分

另外一种是
#ifndef 标识符
  语句组1
[#else
  语句组2 
] 
#endif
[]可选部分


#include<iostream>
using namespace std;

#define md
#ifdef md
void f1(){
	cout << "md is defined!
";
}
#else
void f1(){
	cout << "md not defined!
";
}
#endif

int main()
{
	f1();
	return 0;
}

  

原文地址:https://www.cnblogs.com/mch5201314/p/11686061.html