我想读取浮动文件中的正好70x50数字到二维数组中。当我读取文件和cout数组中的数据时,我会得到正确的数字。但是当我读取文件后,当我尝试使用数组中的数据时,那么数据就是乱码。在读取文件之后,我是否需要分配堆内存来保存?代码如下:从文本文件读取浮动工作,直到出了ifstream范围C++
int main() {
fstream file("numbers.txt");
if (!file) {
cerr << "Sample data could not be opened" << endl;
system("PAUSE");
exit(1);
}
float data[70][50];
for (int i = 0; i < 70; i++){
for (int j = 0; j < 50; j++) {
float n;
file>> n;
data[i][j] = n;
cout << data[i][j];
}
}
cout << data[70][50];
system("PAUSE");
face.close();
return(0);
}
啊从matlab到C++,忘了零索引。谢谢! – user3316012 2014-11-06 20:58:54