问题十一:用条件编译(#if…#endif)避免 main函数中测试代码在测试完成后就删除

来源:互联网 发布:java写hello world 编辑:程序博客网 时间:2024/06/06 17:42

#define testNumber 3

/*

1: output the first image

2: test "int &ri,int& ri,int*&pri"

3: output the first image by using vector.

*/

 

#if testNumber == 1 /*1: output the first image*/

//完整的测试代码1

#elif testNumber == 2 /*2: test "int &ri,int& ri,int*&pri"*/

//完整的测试代码2

#elif testNumber == 3 /*3: output the first image by using vector.*/

//完整的测试代码3

#endif // testNumber

 

可以通过修改宏定义中testNumber的值来控制编译的代码块,也就是控制测试模块。

想测试哪一块,就将testNumber修改成对应的值即可;

想添加一个新的测试块,在添加一个“#elif testNumber == …”即可。

 

4 0
原创粉丝点击