// DebugMethodWithC++.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
//定义DEBUG符合 1的定义参见变种三
#define DEBUG 1
//范围调试
#define LEVE_Z 0//调试级别最低临界点
#define LEVE_A 1//调试级别1
#define LEVE_B 2//调试级别2
#define LEVE_C 3//调试级别3
//特定测试用途
#define POINTER_ERROR 101//特殊用途
//方式一:常规方式 缺点:ifdef代码散布在项目各处。
#ifdef DEBUG
//行为....
#else if
//...行为
#endif
//方式二:变种一 优化:常规方式的优化,提供了#ifdef的封装
#ifdef DEBUG
#define DebugCode(code_fragmant){code_fragmant}
#else if
#define DebugCode(code_fragmant)
#endif
//方式三:变种二 优化:变种一的优化
//使用示列:
//1.DEBUG>POINTER_ERROR 特定用途
//2.DEBUG>LEVE_Z 保留所有调试代码
//3.DEBUG>LEVE_A 设定调试级别的范围
//4.DEBUG==LEVE_A 设定特定的调试级别
#if DEBUG>LEVE_Z
#define DebugCode(code_fragmant){code_fragmant}
#else if
#define DebugCode(code_fragmant)
#endif
int _tmain(int argc, _TCHAR* argv[])
{
string s_temp;
cout<<"please input string.."<<endl;
cin>>s_temp;
DebugCode(cout<<"s_temp var="<<s_temp<<endl;);
cout<<"please press enter exit..."<<endl;
cin>>s_temp;
return 0;
}