C++ – Runtime how to determine Debug or release mode in visual studio c++

c++, debugging, macros, release, visual-studio-2012

I am doing my school assignment. During debug mode I would like to turn on my console mode and during release turn off console.

I have try marco as recommended in stackoverflow but it is not working. I am using visual studio 2012 (empty project c++)

#if DEBUG //doing something#else //Release mode doing something#endif

Best Solution

#if DEBUG will only work if you define DEBUG via the compiler options.

By default, DEBUG is not defined, but _DEBUG is. Try #if defined(_DEBUG), or change your compiler options (via Project Properties / Configuration Properties / C/C++ / Preprocessor / Preprocessor Definitions) to define DEBUG.