本文來源於百度百科http://baike.baidu.com/link?url=rQwTT6H2pjh-38oEvRrPP5HdSCvCpDJBgcNbvBrWp2uaXuzcS6rKPB-Qy5Otu_zfUCHWFBFrE_Dl1IvpUH9iNa
1
2
3
|
#ifdef語句1 //程序2 #endif |
1
2
3
4
5
6
7
8
9
|
#include <iostream> using namespace std; int main( int argc, char *argv[]) { #ifdef DEBUG cout << "Beginning execution of main()" << endl; #endif return 0; } |
1
|
Press any key to continue |
1
2
3
4
5
6
7
8
9
10
|
#include <iostream> using namespace std; #define DEBUG int main( int argc, char *argv[]) { #ifdef DEBUG cout << "Beginning execution of main()" << endl; #endif return 0; } |
1
2
|
Beginning execution of main() Press any key to continue |
1
2
3
|
#define DEBUG #ifdef DEBUG #endif |
1
2
3
4
5
6
7
8
9
|
#include <iostream> #include "head.h" int main( int argc, char *argv[]) { #ifdef DEBUG cout << "Beginning execution of main()" << endl; #endif return 0; } |
1
2
|
Beginning execution of main() Press any key to continue |
1
2
3
4
5
|
#ifdef 標識符 //程序段1 #else //程序段2 #endif |
1
2
3
|
#ifdef 標識符 //程序段1 #endif |
1
2
3
4
5
|
#ifdef WINDOWS #define MYTYPE long #else #define MYTYPE float #endif |
1
|
#define WINDOWS |
1
|
#define MYTYPE long |
1
|
#define WINDOWS |
1
2
3
|
#ifdef DEBUG print( "device_open(%p)\n" ,file); #endif |
1
|
#define DEBUG |
1
2
3
4
5
|
#ifndef 標識符 //程序段1 #else //程序段2 #endif |
1
2
3
4
5
|
#if 表達式 //程序段1 #else //程序段2 #endif |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
#define LETTER 1 int main( int argc, char *argv[]) { char str[20] = "CLanguage" ; char c; int i=0; while ((c = str[i]) != '\0' ) { i++; # if LETTER if (c>= 'a' &&c<= 'z' ) c=c-32; # else if (c>= 'A' &&c<= 'Z' ) c=c+32; #endif printf ( "%c" ,c); } return0; } |
1
|
CLANGUAGE |
1
|
#define LETTER 0 |
1
|
clanguage |