intmain() { #ifdef PRINT_JOE std::cout << "Joe\n"; // will be compiled since PRINT_JOE is defined #endif
#ifdef PRINT_BOB std::cout << "Bob\n"; // will be excluded since PRINT_BOB is not defined #endif
return0; }
1
Joe
**#if 1 **和 **#if 0 **
1 2 3 4 5 6 7 8 9 10 11 12 13
#include<iostream>
intmain() { std::cout << "Joe\n";
#if 0 // Don't compile anything starting here std::cout << "Bob\n"; std::cout << "Steve\n"; #endif// until this point
return0; }
1
Joe
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include<iostream>
intmain() { std::cout << "Joe\n";
#if 1 // always true, so the following code will be compiled std::cout << "Bob\n"; /* Some * multi-line * comment here */ std::cout << "Steve\n"; #endif