不知道各位遇到过这种情况没?编译和连接通过,自己又检查不出程序在中的错误,下面我给了出错的例子.
运行时弹出一个对话框:对话框的内容大致如下:(假设我的可执行文件名为:we.exe)
we.exe遇到问题需要关闭.我们对此引起的不便表示抱歉.
请将此问题报告给Microsoft.
该对话框上有三个按扭,分别是:调试,发送错误报告,不发送.
下面是我的一个例子:计算算术表达式的值..
不看该例子也无妨
如果你有更好的例子,不妨贴上来.
请把你的宝贵经验拿出来大家分享分享吧!谢谢啦!!!!
#include<string>
#include<map>
#include<stack>
#include<iostream>
#include<ctype.h>
using namespace std;
int main()
{
map<string, char>table;
table["++"]=>;
table["+-"]=>;
table["+*"]=<;
table["+/"]=<;
table["+("]=<;
table["+)"]=>;
table["+#"]=>;
table["-+"]=>;
table["--"]=>;
table["-*"]=<;
table["-/"]=<;
table["-("]=<;
table["-)"]=>;
table["-#"]=>;
table["*+"]=>;
table["*-"]=>;
table["**"]=>;
table["*/"]=>;
table["*("]=<;
table["*)"]=>;
table["*#"]=>;
table["/+"]=>;
table["/-"]=>;
table["/*"]=>;
table["//"]=>;
table["/("]=<;
table["/)"]=>;
table["/#"]=>;
table[")+"]=>;
table[")-"]=>;
table[")*"]=>;
table[")/"]=>;
table["))"]=>;
table[")#"]=>;
table["(+"]=<;
table["(-"]=<;
table["(*"]=<;
table["(/"]=<;
table["(("]=<;
table["()"]==;
table["#+"]=<;
table["#-"]=<;
table["#*"]=<;
table["#/"]=<;
table["#("]=<;
table["##"]==;
stack<float> num;
stack<char> alp;
alp.push(#);
string s="2+4-(3-4*3)/4";
s+="#";
int i=0;
char c;
while(c!=#||alp.top!=#)
{
if(isdigit(c))
{
num.push((int)c);
if(i<s.size())
c=s[i++];
}
else
{
char* s1;
s1[0]=alp.top();
s1[1]=c;
string s2=s1;
char c1=table[s2];
switch(c1)
{
case<:
alp.push(c);
c=s[i++];
break;
case=:
alp.pop();
c=s[i++];
break;
case>:
int x=num.top();
num.pop();
int y=num.top();
num.pop();
char c2=alp.top();
alp.pop();
switch(c2)
{
case+:
x=x+y;
break;
case-:
x=x-y;
break;
case*:
x=x*y;
break;
case/:
x=x/y;
break;
}
num.push(x);
break;
}
}
}
cout<<num.top();
}
char* s1;
s1[0]=alp.top(); //出错
s1[1]=c; // 出错,好多自己找
string s2=s1;
char c1=table[s2];
test2 null test 含 空格
assert含义…… 条件不满足 则断言失败 输出诊断信息
到test2 是条件就不满足了 所以出现楼主说的现象啊
你可以做这个测试 DEBUG下看看
先取消第1个NULL的断言
就可以通过test1 test2
因为这个对TEST2来说为假 所以失败了
/* ASSERT.C: In this program, the analyze_string function uses
* the assert function to test several conditions related to
* string and length. If any of the conditions fails, the program
* prints a message indicating what caused the failure.
*/
从你程序上的这段话就能解释啊……让我白说那么多
没看代码,但一般这种情况都和指针或是数组越界有关,自己小心点就好了。