当前位置:首页 > 开发 > 编程语言 > C/C++ > 正文

(Visual studio)C++ 中assert带自定义的消息

发表于: 2012-11-23   作者:cherishLC   来源:转载   浏览:
摘要: 直接贴文件如下: #ifdef NDEBUG #define assert(_Expression) ((void)0) #define assertMsg(_Expression, _Msg) ((void)0) #else #include <crtdefs.h> #include "assert.h" #define as
直接贴文件如下:
#ifdef  NDEBUG
#define assert(_Expression)     ((void)0)
#define assertMsg(_Expression, _Msg) ((void)0)
#else
	#include <crtdefs.h>
	#include "assert.h"
	#define assert(_Expression) (void)( (!!(_Expression)) || (_wassert(_CRT_WIDE(#_Expression), _CRT_WIDE(__FILE__), __LINE__), 0) )
	#define assertMsg(_Expression, _Msg) (void)( (!!(_Expression)) || (_wassert(_CRT_WIDE(_Msg), _CRT_WIDE(__FILE__), __LINE__), 0) )
#endif

参考自: http://social.msdn.microsoft.com/forums/en-US/vclanguage/thread/828b708c-e186-4774-b0fc-f45ddf49163b

另有一种不太好看的:
assert(a == b && "A is not equal to B");

参考自: http://stackoverflow.com/questions/3692954/add-custom-messages-in-assert

(Visual studio)C++ 中assert带自定义的消息

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号