预处理
#includeusing namespace std; #define DEBUG #define MIN(a,b) (((a)<(b)) ? a : b) int main () { int i, j; i = 100; j = 30; #ifdef DEBUG cerr <<"Trace: Inside main function" << endl; #endif #if 0 cout << MKSTR(HELLO C++) << endl; #endif cout <<"The minimum is " << MIN(i, j) << endl; #ifdef DEBUG cerr <<"Trace: Coming out of main function" << endl; #endif return 0; }
预处理更多例子。
你可以这么写:
1. #if SOMETHING>=100 //... #else //... #endif
2. #ifndef SOMETHING_H #define SOMETHING_H //... #endif
3. #if (defined DEBUG)&&(defined SOMETHING) //... #endif
4.
#ifdef SOMETHING
int func1(){}
#else
int func1(){}
#endif
5.
#ifdef SOMETHING
namespace space1{
#endif
//...
#ifdef SOMETHING
}//space1
#endif 还有很多。



