assert俗称断言,个人认为称有校性校验更准确,这里是它的用法,亲测通过

来源:互联网 发布:php date 取时间 编辑:程序博客网 时间:2024/04/20 09:59
#include <iostream>#include <assert.h>// #define _NDEBUG#ifndef _NDEBUG    #define _DEBUG#endif // _DEBUGusing namespace std;bool TestValue(int a){    if ( a > 100 )        return false;    else        return true;}int main(){    int x = 10;    #ifdef _DEBUG    assert( TestValue(x) );    #endif    cout << "Hello world!" << endl;    x = 20;    assert( TestValue(x) );    cout << "New Hello World!" << endl;    x = 120;    #ifdef _DEBUG    assert( TestValue(x) );    #endif    cout << "The last line output!!!" << endl;    return 0;}

// 整体上很简单,思路也比较清楚了,不必做注释,复制下来跑一遍就啥都明白了。