【发布时间】:2017-03-18 14:07:20
【问题描述】:
我正在尝试读取一个非常大的 .txt 文件,该文件具有 128x128x128=2097152 行(线性化 3d 空间),其中仅包含一个 0 或 1 行(不要问为什么)...我将我的代码修剪为几行,似乎当我计算线和增量时,一切都很顺利......但是一旦我想将数据放入足够允许的数组中,行读取停止在 i=12286...
这是代码
int dim = nbvox[0]*nbvox[1]*nbvox[2];
float* hu_geometry = new float(dim);
int* hu_temp = new int(dim);
string line;
int i = 0;
ifstream in(hu_geom_file.c_str());
if(in.is_open())
{
while(getline(in, line))
{
hu_temp[i] = stoi(line);
cout << "i= " << i << " line= " << line << " hu_temp= " << hu_temp[i] << endl;
i++;
}
cout << __LINE__ << " i=" << i << endl;
in.close();
cout << __LINE__ << endl;
}
else cout << "Unable to open " << hu_geom_file << endl;
这是我在收到错误之前得到的最后一个输出......这很奇怪,因为每当我在 while 中评论 hu_temp 行时,cout 单独工作到 2097152。
i= 12276 line= 0 hu_temp= 0
i= 12277 line= 0 hu_temp= 0
i= 12278 line= 0 hu_temp= 0
i= 12279 line= 0 hu_temp= 0
i= 12280 line= 0 hu_temp= 0
i= 12281 line= 0 hu_temp= 0
i= 12282 line= 0 hu_temp= 0
i= 12283 line= 0 hu_temp= 0
i= 12284 line= 0 hu_temp= 0
i= 12285 line= 0 hu_temp= 0
115 i=12286
*** Error in `G4Sandbox': free(): invalid pointer: 0x0000000001ba4c40 ***
Aborted (core dumped)
【问题讨论】:
标签: c++