当前位置:首页
开发技术指南» 文章正文
    引言:

    摘要: 请看: http://community.csdn.net/expert/topic/4177/4177697.xml?temp=.636883 ......
    摘要: 欢迎到电脑防毒网论坛申请斑竹 http://www.fangdu.net/bbs ......


不知道各位遇到过这种情况没编译和连接通过,自己又检查不出程序在中的错误,里面我给了出错的例子.

不知道各位遇到过这种情况没?编译和连接通过,自己又检查不出程序在中的错误,下面我给了出错的例子.  
   
  运行时弹出一个对话框:对话框的内容大致如下:(假设我的可执行文件名为: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();  
  }  
   
   
   
 

NO.1   作者: foochow

char*   s1;  
  s1[0]=alp.top();       //出错  
  s1[1]=c;     //   出错,好多自己找  
  string   s2=s1;  
  char   c1=table[s2];

NO.2   作者: windking21

test2   null   test   含   空格  
     
  assert含义……   条件不满足   则断言失败   输出诊断信息    
   
  到test2   是条件就不满足了   所以出现楼主说的现象啊

NO.3   作者: windking21

你可以做这个测试   DEBUG下看看  
   
  先取消第1个NULL的断言  
  就可以通过test1   test2  
   
  因为这个对TEST2来说为假   所以失败了  
   
 

NO.4   作者: windking21

/*   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.  
   
    */  
   
  从你程序上的这段话就能解释啊……让我白说那么多  
 

NO.5   作者: mostideal

没看代码,但一般这种情况都和指针或是数组越界有关,自己小心点就好了。


    摘要: 欢迎到电脑防毒网论坛申请斑竹 http://www.fangdu.net/bbs ......
» 本期热门文章:
· 热门栏目:
» 相关精选文章
» 其它相关:

©2000-2007 All Rights Reserved. 最佳浏览:1024X768 MSIE