条件编译的使用

条件编译是一种很好的编译技巧。

使用条件编译,让有的部分相当于没有

条件编译的例子如下。

#include <iostream>
#include <string>
using namespace std;
#define IS
int main() {

//形式2 将#if 1 变成0 看效果
#if 1
	int k = 0;
#else
	string k = "stringk";
#endif
	cout << "the value of k is: " << k << endl;

//形式4 注释掉#difine IS看效果
#ifdef IS
	int i = 1;
#else
	string i = "string";
#endif
	cout << "the value of i is : " << i << endl;
	return 0;
}

[1] C++语言程序设计 郑莉 174页。

posted @ 2017-04-25 15:09  开往春天的拖拉机  阅读(132)  评论(0编辑  收藏  举报