bun*_*uru 2 c++ arrays fstream vector ifstream
我有一个由数千个浮点值组成的数据文件,我想将它们读入一个2D矢量数组,并将该矢量传递给另一个例程,一旦它存储了文件中的浮点数.当我运行此代码时,它打印出来;
[0] [0] = 0,[0] [1] = 0等
数据文件包含的值如下;
0.000579,27.560021等
int rows = 1000;
int cols = 2;
vector<vector<float>> dataVec(rows,vector<float>(cols));
ifstream in;
in.open("Data.txt");
for(int i = 0; i < rows; i++){
for(int j = 0; j < 2; j++){
in >> dataVec[i][j];
cout << "[ " << i << "][ " << j << "] = " << dataVec[i][j] << endl;
}
}
in.close();
Run Code Online (Sandbox Code Playgroud)