开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜