跪求C++程序设计!!!!急!!!!

来源:百度知道 编辑:UC知道 时间:2024/06/19 15:40:13
试创建一个正式文件用于存放一个矩阵(即二维数组),文件的第一行有两个整数,分别表示矩阵的行、列数(m和n),后面的数据共分m行,每行有n个实数。

#include <stdlib.h>
#include <iostream.h>
#include <fstream.h>
#define ROW 3
#define COL 5

void main()
{
float a[ROW][COL];
int i, j;
ofstream outfile("data.txt");

if (!outfile)
{
cout << "Can not open file." << endl;
exit(-1);
}

cout << "Please input a matrix's data(" << ROW << " row and " << COL << " column)" << endl;
outfile << ROW << ' ' << COL << endl;

for (i = 0; i < ROW; ++i)
{
for (j = 0; j < COL - 1; ++j)
{
cin >> a[i][j];
outfile << a[i][j] << ' ';
}

cin >> a[i][j];
outfile << a[i][j] << endl;
}

outfile.close();
system("PAUSE");
}

#define M 3
#