[英]How to avoid CRT dialog with assert(..) function
Is there a way in Windows to avoid CRT dialog on failure with assert(..) function? Windows中有没有一种方法可以避免使用assert(..)函数失败时进行CRT对话框? 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?
如果我们没有在优化版本中定义NDEBUG来实现此目标,可以使用CrtReportMode(..)吗?
-Kartlee -Kartlee
You can use _CrtSetReportMode
and _CrtSetReportFile
to send the output to a file (in this case stderr
) instead. 您可以使用
_CrtSetReportMode
和_CrtSetReportFile
将输出发送到文件(在本例中为stderr
)。
_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.
如果未定义_DEBUG,则在预处理期间将删除对_CrtSetReportMode的调用。
Libraries: Debug versions of C Run-Time Libraries only.
库:仅调试版本的C运行时库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.