Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/155.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 将矩阵写入文件_C++_File Io_Matrix_Output - Fatal编程技术网

C++ 将矩阵写入文件

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"); {

我在尝试将矩阵写入文件时遇到问题。我设法打开了一个文本文件,但是没有显示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();
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 ;
}