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

vs2010调试时程序退出咋回事

2012-09-05 
vs2010调试时程序退出怎么回事vs2010调试时程序退出怎么回事//建立储存作者与相应作品信息的multimap容器/

vs2010调试时程序退出怎么回事
vs2010调试时程序退出怎么回事
//建立储存作者与相应作品信息的multimap容器
//支持查并删除。若元素不存在,程序也支持。
# include<iostream>
#include<string>
#include<map>
using namespace std;
typedef multimap<string,string> Au_work;
typedef Au_work::iterator Ait;
int main()
{
  Au_work work_list;
  string sa,sw;
  while(1)
  {
  cout<<"enter author and end all with @"<<endl;
  getline(cin,sa);
  if(sa=="@")
  break;
  cout<<"enter the books' name each end by enter,ctrl+z to end all"<<endl;
  while(getline(cin,sw))
  work_list.insert(make_pair(sa,sw));
  cin.clear();
  }
  while(1)
  {
  cout<<"enter author you want to erase and @ to end all"<<endl;
  getline(cin,sa);
  if(sa=="@")
  break;
  Ait beg=work_list.find(sa),end=work_list.end();
  if(beg==end)
  cout<<"cannot find the record"<<endl;
  else
  work_list.erase(sa);
  }
  cout<<"here"<<endl;///////////////////看这里
  //to check whether the code functions well,print all the authors and work still in the list
  string pa,ca;
  for(Ait beg=work_list.find(sa);beg!=work_list.end();beg++)
  {  
  //ca represents current author,pa represents pricious author
  pa=ca;
  ca=beg->first;
  cout<<((ca==pa)?" ":ca)<<' '<<beg->second<<endl;
  }
  return 0;
}开始时没写显示删除后的那段代码运行时没问题,为了检查有没有真的达到效果,就加了那一段结果一样,他竟没输出,如图。于是调试设了断点,但每次运行到上面注释的 看这里 附近就自动退出了,如图。其实我写其他小程序时也会遇到同样情况,但自己随便改改,不知不觉那个错就没了。
所以很想问这个自动退出一般是什么原因。。。。
后来发现错误是for循环的初始化错了Ait beg=work_list.find(sa);改为
for(Ait beg=work_list.begin();beg!=work_list.end();beg++)
可是还是想问,: 程序自动退出一般是因为什么? 谢谢
 ][/img]

[解决办法]
自动退出一般是程序运行时发生了无法处理的错误
例如堆栈溢出,例如抛出异常未捕获

热点排行