简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM