将矩阵写入txt文件中;每行C 之后

writing a matrix into a txt file with ; after each row C++?

本文关键字:每行 之后 文件 txt      更新时间:2023-10-16

我有一个矩阵" powermatrix",该尺寸为24 * 24,现在我需要知道如何将此矩阵写入带有a的文本文件中;每行之后?我怎样才能做到这一点?到目前为止,我有这个代码,但是我不知道为什么,但是我无法使用A分开;每行之后?

std::ofstream output("Power vector.txt"); 
for (k=1; k<PowerMatrix.size(); k++)
{
for (l=1; l<PowerMatrix.size(); l++)
{
output << PowerMatrix[i][j] << " "; // behaves like cout - cout is also a stream
}
output << "n";
} 

只需在newline之前添加;

std::ofstream output("Power vector.txt"); 
for (k=1; k<PowerMatrix.size(); k++)
{
    for (l=1; l<PowerMatrix.size(); l++)
    {
        output << PowerMatrix[i][j] << " "; // behaves like cout - cout is also a stream
    }
    output << ";" << endl;
}