Win10
GCC
小弟需要将一个txt档的资料存成double型态的二维阵列
资料来源如附图
https://imgur.com/a/bdjQbiR
是一个144列*3行的数据
这是我的code
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
using namespace std;
int main() {
ifstream inFile("Point_After.txt");
const int xsize = 3;
const int ysize = 144;
double (*arr)[xsize] = new double[ysize][xsize];
string line;
int y = 0;
while(getline(inFile,line)) {
istringstream ss(line);
double num;
int x = 0;
while(ss >> num) {
arr[y][x] = num;
++x;
}
++y;
}
inFile.close();
for(int y = 0; y != ysize; ++y) {
for(int x = 0; x != xsize; ++x) {
cout << arr[y][x] << " ";
}
cout << endl;
}
delete []arr;
return 0;
}
这是我执行后的结果
https://imgur.com/a/KakhsWZ
想请问各位前辈为何无法成功
谢谢
主要问题我想出在字串转成double无法成功