C++ examples for Preprocessor:Directive
Use #if to check value
#if LANGUAGE == ENGLISH #define Greeting "Good Morning." #elif LANGUAGE == GERMAN #define Greeting "Guten Tag." #elif LANGUAGE == FRENCH #define Greeting "Bonjour." #else #define Greeting "Hi." #endif std::cout << Greeting << std::endl;
Include different code depending on an identifier that represents a version number:
#if VERSION == 3 // Code for version 3 here... #elif VERSION == 2 // Code for version 2 here... #else // Code for original version 1 here... #endif