Automatic #defines according to Debug/Release config in Visual Studio

I have debug output in my program like this:

#define DEBUG
...
#ifdef DEBUG
    std::cout << "[RE_words] " << m_re << std::endl;
#endif

and DEBUG is defined in my program manually. I always comment out the line when I make a release version. In Visual Studio, there are also Configurations for Debug vs Release versions which handle the commandline etc. used for compiling. Can I also use the Configuration "Debug" to automatically define DEBUG to the compiler? How?


The Visual Studio automatically defines _DEBUG symbol for Debug builds (and NDEBUG for non-debug builds).

Another way to do this is to go to the project settings -> configuration properties -> C/C++ -> preprocessor, and edit the preprocessor definitions manually.

See also:
This answer explains the differences between _DEBUG and NDEBUG in more detail.
This answer explains the purpose of the NDEBUG symbol and whether or not is it defined by the standard.


Use _DEBUG. Visual C++ defines this for a Debug configuration. Check out the preprocessor directives for the Debug Configuration in your project's properties dialog.