How to turn off ASSERTs in debug mode in Visual Studio 2013

You can use _set_error_mode or _CrtSetReportMode (see xMRi's answer) to alter failure reporting method and avoid modal dialog box. See code snippet there:

int main()
{
   _set_error_mode(_OUT_TO_STDERR);
   assert(2+2==5);
}

Also note that assert failures are typically for a reason, and you want to fix code, not just suppress the report. By removing them from debug builds completely you are simply breaking good things built for you.


#define NDEBUG before #include <assert.h> to disable assert macro.

You may so add this to pre-processor definition in project settings.


User _CrtSetReportMode

int iPrev = _CrtSetReportMode(_CRT_ASSERT,0);
// Start Operation with no ASSERTs
...
// Restore previous mode with ASSERTs
_CrtSetReportMode(_CRT_ASSERT,iPrev);

Instead of using 0, you can use _CRTDBG_MODE_DEBUG only.

Tags:

C++

Assert

Mfc