0
由於某些原因,在輸入文件中的值後,矩陣中每個數字的值爲零。它在我用全零初始化矩陣時起作用,但無論出於何種原因,我都無法從文本文件中導入數字。如何將文件中的數字輸入到矩陣中?
struct Vector {
float* els;
int len;
};
struct Matrix {
Vector* col; // col is array of Vectors; each Vector is one column of matrix
int ncols; // total number of columns in matrix
};
...
ifstream fin("mat.def");
fin >> m >> n;
fin >> M;
...
istream& operator>>(istream& input, Matrix& mm) {
int m,n;
n=mm.ncols;
mm.col = new Vector[n]; // use n instead m for consistency
for (int i=0;i<n;i++) {
mm.col[i].els = new float[m];
for (int k=0;k<m;k++) {
input >> mm.col[i].els[k];
}
}
return input;
}