我编写了一个代码,其中包含二维 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/