为什么我的断言没有引发错误?

问题描述

我的断言不会阻止程序继续运行。从这个问题上我从其他问题中已经看到,我没有定义NDEBUG。谁能解释为什么?

#include <iostream>
#include <assert.h>

int main()
{
   assert(0==1);
   std::cout << "Execution continues past the first assert" << std::endl;
   return 0;
}

编辑: 我正在使用VS2019

Edit2: 谢谢Arthur-就像有人提到的那样,NDEBUG似乎定义在某个地方。有没有办法定义这个?

解决方法

编辑:我正在使用VS2019

将构建类型更改为“调试”。

https://docs.microsoft.com/en-us/visualstudio/ide/understanding-build-configurations?view=vs-2019