首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

Dev-C下无法阻止assert让窗口闪灭了!该如何处理

2012-04-21 
Dev-C下无法阻止assert让窗口闪灭了!C/C++ code#includeiostream#includeassert.h#includewindows.h

Dev-C下无法阻止assert让窗口闪灭了!

C/C++ code
#include<iostream>#include<assert.h>#include<windows.h>#include<stdlib.h>#include<stdio.h>using namespace std;int test(int a,int b){              cout<<"acd"<<endl;              if(a+b>6)              {               assert(!"Should never get here!");               system("pause");               return -1;              }              return a+b;     }int main(){    int m=test(6,1);    cout<<"m = "<<m;    //test(1,2);    getchar();    system("pause");    return 0;}

跟assert有关,但不知道为什么。
闪灭,你懂得。

[解决办法]
断言失败,灭了不正常吗?
[解决办法]
探讨
引用:

可能是实现相关吧。。
改成下面这样试试?
C/C++ code

#include<iostream>
#include<assert.h>
#include<windows.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;

int test(int a,int b){
……

[解决办法]
assert一般用于debug版本 抓一些你认为不会出现的问题. 好处是弹出框后可以直接调试.

默认好像内部会调用exit 可以通过设置 让他不调用exit. 你可以跟进去看看就知道设置什么可以让他不退出了.

热点排行
Bad Request.