运行时弹出一个对话框:对话框的内容大致如下:(假设我的可执行文件名为: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();
}
9 个解决方案
#1
还有一种情况也另我很不知所措.
运行时跳错一个这样的对话框:
对话框大致的内容如下:
Debuge Error!
abnormal programe termination!
里面也有三个按扭,分别是:终止,调试,忽略.
下面也给出一个例子.什么情况下会出现这两种情况呢???
又该怎么解决呢????
/* 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.
*/
#include <stdio.h>
#include <assert.h>
#include <string.h>
void analyze_string( char *string ); /* Prototype */
void main( void )
{
char test1[] = "abc", *test2 = NULL, test3[] = "";
printf ( "Analyzing string '%s'\n", test1 );
analyze_string( test1 );
printf ( "Analyzing string '%s'\n", test2 );
analyze_string( test2 );
printf ( "Analyzing string '%s'\n", test3 );
analyze_string( test3 );
}
/* Tests a string to see if it is NULL, */
/* empty, or longer than 0 characters */
void analyze_string( char * string )
{
assert( string != NULL ); /* Cannot be NULL */
assert( *string != '\0' ); /* Cannot be empty */
assert( strlen( string ) > 2 ); /* Length must exceed 2 */
}
/*Output
Analyzing string 'abc'
Analyzing string '(null)'
Assertion failed: string != NULL, file assert.c, line 24
abnormal program termination*/
运行时跳错一个这样的对话框:
对话框大致的内容如下:
Debuge Error!
abnormal programe termination!
里面也有三个按扭,分别是:终止,调试,忽略.
下面也给出一个例子.什么情况下会出现这两种情况呢???
又该怎么解决呢????
/* 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.
*/
#include <stdio.h>
#include <assert.h>
#include <string.h>
void analyze_string( char *string ); /* Prototype */
void main( void )
{
char test1[] = "abc", *test2 = NULL, test3[] = "";
printf ( "Analyzing string '%s'\n", test1 );
analyze_string( test1 );
printf ( "Analyzing string '%s'\n", test2 );
analyze_string( test2 );
printf ( "Analyzing string '%s'\n", test3 );
analyze_string( test3 );
}
/* Tests a string to see if it is NULL, */
/* empty, or longer than 0 characters */
void analyze_string( char * string )
{
assert( string != NULL ); /* Cannot be NULL */
assert( *string != '\0' ); /* Cannot be empty */
assert( strlen( string ) > 2 ); /* Length must exceed 2 */
}
/*Output
Analyzing string 'abc'
Analyzing string '(null)'
Assertion failed: string != NULL, file assert.c, line 24
abnormal program termination*/
#2
char* s1;
s1[0]=alp.top(); //出错
s1[1]=c; // 出错,好多自己找
string s2=s1;
char c1=table[s2];
s1[0]=alp.top(); //出错
s1[1]=c; // 出错,好多自己找
string s2=s1;
char c1=table[s2];
#3
谢谢,这的确是一个严重的错误:野指针.
#4
下面也给出一个例子.什么情况下会出现这两种情况呢???
又该怎么解决呢????
又该怎么解决呢????
#5
test2 null test 含 空格
assert含义…… 条件不满足 则断言失败 输出诊断信息
到test2 是条件就不满足了 所以出现楼主说的现象啊
assert含义…… 条件不满足 则断言失败 输出诊断信息
到test2 是条件就不满足了 所以出现楼主说的现象啊
#6
你可以做这个测试 DEBUG下看看
先取消第1个NULL的断言
就可以通过test1 test2
因为这个对TEST2来说为假 所以失败了
先取消第1个NULL的断言
就可以通过test1 test2
因为这个对TEST2来说为假 所以失败了
#7
/* 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.
*/
从你程序上的这段话就能解释啊……让我白说那么多
* 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.
*/
从你程序上的这段话就能解释啊……让我白说那么多
#8
谢谢以上的各位.
#9
没看代码,但一般这种情况都和指针或是数组越界有关,自己小心点就好了。
#1
还有一种情况也另我很不知所措.
运行时跳错一个这样的对话框:
对话框大致的内容如下:
Debuge Error!
abnormal programe termination!
里面也有三个按扭,分别是:终止,调试,忽略.
下面也给出一个例子.什么情况下会出现这两种情况呢???
又该怎么解决呢????
/* 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.
*/
#include <stdio.h>
#include <assert.h>
#include <string.h>
void analyze_string( char *string ); /* Prototype */
void main( void )
{
char test1[] = "abc", *test2 = NULL, test3[] = "";
printf ( "Analyzing string '%s'\n", test1 );
analyze_string( test1 );
printf ( "Analyzing string '%s'\n", test2 );
analyze_string( test2 );
printf ( "Analyzing string '%s'\n", test3 );
analyze_string( test3 );
}
/* Tests a string to see if it is NULL, */
/* empty, or longer than 0 characters */
void analyze_string( char * string )
{
assert( string != NULL ); /* Cannot be NULL */
assert( *string != '\0' ); /* Cannot be empty */
assert( strlen( string ) > 2 ); /* Length must exceed 2 */
}
/*Output
Analyzing string 'abc'
Analyzing string '(null)'
Assertion failed: string != NULL, file assert.c, line 24
abnormal program termination*/
运行时跳错一个这样的对话框:
对话框大致的内容如下:
Debuge Error!
abnormal programe termination!
里面也有三个按扭,分别是:终止,调试,忽略.
下面也给出一个例子.什么情况下会出现这两种情况呢???
又该怎么解决呢????
/* 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.
*/
#include <stdio.h>
#include <assert.h>
#include <string.h>
void analyze_string( char *string ); /* Prototype */
void main( void )
{
char test1[] = "abc", *test2 = NULL, test3[] = "";
printf ( "Analyzing string '%s'\n", test1 );
analyze_string( test1 );
printf ( "Analyzing string '%s'\n", test2 );
analyze_string( test2 );
printf ( "Analyzing string '%s'\n", test3 );
analyze_string( test3 );
}
/* Tests a string to see if it is NULL, */
/* empty, or longer than 0 characters */
void analyze_string( char * string )
{
assert( string != NULL ); /* Cannot be NULL */
assert( *string != '\0' ); /* Cannot be empty */
assert( strlen( string ) > 2 ); /* Length must exceed 2 */
}
/*Output
Analyzing string 'abc'
Analyzing string '(null)'
Assertion failed: string != NULL, file assert.c, line 24
abnormal program termination*/
#2
char* s1;
s1[0]=alp.top(); //出错
s1[1]=c; // 出错,好多自己找
string s2=s1;
char c1=table[s2];
s1[0]=alp.top(); //出错
s1[1]=c; // 出错,好多自己找
string s2=s1;
char c1=table[s2];
#3
谢谢,这的确是一个严重的错误:野指针.
#4
下面也给出一个例子.什么情况下会出现这两种情况呢???
又该怎么解决呢????
又该怎么解决呢????
#5
test2 null test 含 空格
assert含义…… 条件不满足 则断言失败 输出诊断信息
到test2 是条件就不满足了 所以出现楼主说的现象啊
assert含义…… 条件不满足 则断言失败 输出诊断信息
到test2 是条件就不满足了 所以出现楼主说的现象啊
#6
你可以做这个测试 DEBUG下看看
先取消第1个NULL的断言
就可以通过test1 test2
因为这个对TEST2来说为假 所以失败了
先取消第1个NULL的断言
就可以通过test1 test2
因为这个对TEST2来说为假 所以失败了
#7
/* 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.
*/
从你程序上的这段话就能解释啊……让我白说那么多
* 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.
*/
从你程序上的这段话就能解释啊……让我白说那么多
#8
谢谢以上的各位.
#9
没看代码,但一般这种情况都和指针或是数组越界有关,自己小心点就好了。