文件示例; 方阵; #之后的矩阵大小
#3
1.1 -0.2 0.1
0.1 -1.2 -0.2
0.2 -0.1 1.1
Run Code Online (Sandbox Code Playgroud)
大约如此我会用C写的
double **A;
int i,j,size=0;
FILE *f=NULL;
f=fopen("input.txt","w");
fscanf(f,"#%d\n",&size);
A=(double**)malloc(size*sizeof(double*));
for(i=0;i<size;i++)
A[i]=(double*)malloc(size*sizeof(double));
for(i=0;i<size;i++)
{
for(j=0;j<size;j++)
{
fscanf(f,"%lf",&A[i][j]);
}
}
fclose(f);
Run Code Online (Sandbox Code Playgroud)
我试图使用方法"read_to_string"并解析String,但我对String和str之间的转换感到困惑.