C++向assert加入错误信息

需求

程序使用assert(bool_expression)进行断言,希望能在中断时给出提示信息。

实现

使用&&连接表达式,字符串作为非空指针,bool值为true不会影响结果。

assert(a == b && "A is not equal to B");

参考

c++ - Add custom messages in assert? - Stack Overflow

原文地址:https://www.cnblogs.com/azureology/p/15790104.html