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!\n";
}
#else
void f1(){
	cout << "md not defined!\n";
}
#endif

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

  

 

posted @ 2019-10-16 16:00  ChunhaoMo  阅读(246)  评论(0编辑  收藏  举报