是否可以在断言错误时写一条消息?
例如,使用 #include <assert.h>
,我只能写:
void foo(int a, int b) {
assert (a != b);
}
但是,如果出现错误,我想查看 a
的值和 b
.我该怎么做?
最佳答案
我通常只使用 assert(a != b && "This is my error message")
。这是可行的,因为 char*
可以转换为 bool,而且它永远不会为 false(因为地址不是 0)。
关于c++ - 将 assert() 与消息一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16775967/