C++编程思想 第1卷 第3章 调试技巧 C语言assert()宏

标准头文件<cassert>中,assert()是一个方便的调试宏
当使用assert()时,给它一个参数,一个断言为真的表达式
如果断言不为真,会发出错误信息
错误信息是断言是什么

程序失败后,会终止


//: C03:Assert.cpp
// From Thinking in C++, 2nd Edition
// Available at http://www.BruceEckel.com
// (c) Bruce Eckel 2000
// Copyright notice in Copyright.txt
// Use of the assert() debugging macro
#include <cassert>  // Contains the macro
using namespace std;


int main() {
  int i = 100;
  assert(i != 100); // Fails
} ///:~


这个宏来源于标准C,所以在头文件assert.h中也可以使用


输出
assert faild i!=100 路径省略 失败退出

猜你喜欢

转载自blog.csdn.net/eyetired/article/details/80786141