开发者

How to avoid CRT dialog with assert(..) function

开发者 https://www.devze.com 2023-04-03 08:10 出处:网络
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 def

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消