Is there a way in Windows to avoid CRT dialog on failure with assert(..) function? I like to get the error 开发者_运维技巧message printed to the console. Can CrtReportMode(..) be used if we don't define NDEBUG in optimized version to achieve this?
-Kartlee
You can use _CrtSetReportMode
and _CrtSetReportFile
to send the output to a file (in this case stderr
) instead.
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE)
_CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDERR );
Regarding the use in a release build, note the remarks and libraries sections:
When _DEBUG is not defined, calls to _CrtSetReportMode are removed during preprocessing.
Libraries: Debug versions of C Run-Time Libraries only.
精彩评论