Условная компиляция #ifdef #endif #else #ifndef #if
#define DEBUG
int main()
{
#ifdef DEBUG // если DEBUG объявлен, то выведится текст "debug"
cout << "debug" << endl;
#else // иначе
cout << "release" << endl;
#endif
}


#ifndef - это инвертированная версия #ifdef

#if - проверяет условие
#elif - дополнительное условие
#define DEBUG -1
#if DEBUG > 0
cout << "debug" << endl;
#elif DEBUG <= -1
cout << "error" << endl;
#else
cout << "release" << endl;
#endif

Last updated