我在尝试将矩阵写入文件时遇到问题。我设法打开了一个文本文件,但显示的不是 3x3 矩阵,而是一个很长的数字,这是一个错误。
我的代码是
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();
解决方案可能非常简单,但我无法在线找到解决方案!
最佳答案
你需要单独写出矩阵元素
out << sum[0][0] << "," << sum[0][1] << etc.
关于c++ - 将矩阵写入文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23340437/