一个double型二维数组Q[5][4],一个txt文件内有一列20个数据将txt文件内的输入依次读出并对二维数组赋值将二维数组内的值依次保存到另一个txt中,成一列20个数据怎么利用visual c++ 6.0 实现?求高手!!!
//从123.txt读数据,将读到的数据输入456.txt中#include <stdio.h>#include <stdlib.h>int main(void){ int i, j; double Q[5][4]; FILE *fp; if (NULL == (fp = fopen("123.txt", "r"))) { printf("file not open!\n"); exit(0); } for (i=0; i<5; i++) { for (j=0; j<4; j++) { fscanf(fp, "%lf", &Q[i][j]); } } fclose(fp); if (NULL == (fp = fopen("456.txt", "w"))) { printf("file not open!\n"); exit(0); } for (i=0; i<5; i++) { for (j=0; j<4; j++) { fprintf(fp, "%lf\n", Q[i][j]); } } fclose(fp); return 0;}
#include <iostream>#include <fstream>using namespace std;int main(){ double Q[5][4]; ifstream fin("a.txt");//a.txt读入de文件 ofstream fout("b.txt");//b.txt输出de文件 char ch[20]; for(int i=0;i<5;i++) for(int j=0;j<4;j++) { fin>>ch; fout<<ch<<endl; Q[i][j]=atof(ch); cout<<Q[i][j]<<endl; } fin.close(); fout.close(); return 0;}
#include <stdio.h>int main() { int i,j; double Q[5][4]; FILE *InputFP,*OutFP; InputFP = fopen("F:\\VC\\in.txt","rt"); for(i = 0;i < 5;i++) { for(j = 0;j < 4;j++) { fscanf(InputFP,"%lf",&Q[i][j]); printf("%7.2lf\n",Q[i][j]); } } printf("\n"); fclose(InputFP); OutFP = fopen("F:\\VC\\out.txt","wt"); for(i = 0;i < 5;i++) { for(j = 0;j < 4;j++) { fprintf(OutFP,"%7.2lf",Q[i][j]); } } fclose(OutFP); return 0;}