C++ 将矩阵写入文件
我在尝试将矩阵写入文件时遇到问题。我设法打开了一个文本文件,但是没有显示3x3矩阵,而是显示了一个很长的数字,这是一个错误 我的密码是C++ 将矩阵写入文件,c++,file-io,matrix,output,C++,File Io,Matrix,Output,我在尝试将矩阵写入文件时遇到问题。我设法打开了一个文本文件,但是没有显示3x3矩阵,而是显示了一个很长的数字,这是一个错误 我的密码是 outf.open("Out2.txt"); cout<<"Please enter the output file(Out2.txt\n"; cin>>outfile; if (outfile == "Out2.txt"); {
outf.open("Out2.txt");
cout<<"Please enter the output file(Out2.txt\n";
cin>>outfile;
if (outfile == "Out2.txt");
{
outf<<"The sum of Matrix X and Matrix Y is:"<<sum[3][3];
}
outf.close();
outp.open(“Out2.txt”);
coutoutfile;
如果(outfile==“Out2.txt”);
{
outf您需要单独写出矩阵元素
out << sum[0][0] << "," << sum[0][1] << etc.
out线路
outf<<"The sum of Matrix X and Matrix Y is:"<<sum[3][3];
可能是您正在联机搜索如何在文件中写入矩阵,而不是搜索如何将二维或三维数组写入文件。如果
for(int lin=0;line<nb_lines;lin++)
{
for(int col=0;col<max_col;col++)
{
ouf << sum[lin][col] << " " ;
}
ouf << std::endl ;
}