c++ - C++运行时中的奇怪错误

标签 c++ debugging error-handling compiler-errors runtime-error

我编写了一个代码,其中包含二维 vector 作为组件。每当我输入时,1/2 秒后它会显示此错误

"Terminate called after throwing an instance of ‘std::bad_alloc’ 
What(): std::bad_alloc

This application has requested the Runtime to terminate it in an unusual way. 
Please contact the application’s support team for more information."

之后,我的 PC 速度变慢,代码返回一个整数,直到我关闭 .exe 文件,它才恢复速度。

这背后的原因是什么?如何避免此类错误?\ 我的密码是 http://paste.ubuntu.com/6593192/

最佳答案

也许 int i 的重复导致了问题?

int main()
{
  **int i;** //1st
  vector<int > a(6); vector<vector<int> > c;  //two vectors
  for(**int i**=0;i<6;++i)//2nd
    cin>>a[i]; //use the 2nd

  c=mco(a,i);//use the 1st, and it is uninitialized yet!

奇怪的是这不是错误。这两个“i”实际上是在同一范围内声明的。即使 2nd 只在 1st for,也没有作用域。

在 VS10 中,我有一个未初始化的局部变量警告。

关于c++ - C++运行时中的奇怪错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20653448/

相关文章:

c++ - 发生内存不足错误时怎么办?

angular - 使用 ngrx 处理组件错误

c++ - 我可以设置 array[n+k] = array[0] 吗?

c++ - 如何获取与 Linux 桌面中的文件关联的图标、MIME 类型和应用程序?

c++ - 添加两个多项式并正确显示结果

c++ - 使用 make 有条件地设置调试宏

c++ - 使类信息在运行时可访问的可扩展方式

python - 如何使用带有选项卡完成功能的 python 调试器运行 pytest?

debugging - 如何在gdb中禁用 "Type <return> to continue, or q <return> to quit"?

python - 引发错误后如何在数据框中标记损坏的数据