#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
float x[1000][1000];
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我得到"s.exe中0x01341637的第一次机会异常:0xC00000FD:堆栈溢出." 为什么?
你的数组太大而无法放在堆栈上.您没有足够的堆栈空间用于1000 * 1000元素.
您需要在堆上分配数组.您可以使用new关键字执行此操作,但更简单的方法是使用std::vector.
std::vector<std::vector<float> > floats(1000);
for (unsigned i = 0; i != floats.size(); ++i) floats[i].resize(1000);
Run Code Online (Sandbox Code Playgroud)
这将为您提供浮动的二维向量,每个向量包含1000个元素.
另请参阅:大数组大小的分段错误