简体   繁体   中英

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

I have a matrix " PowerMatrix" which is of size 24 * 24 now i need to know how can i write this matrix into a text file with a ; after each row? how can i do this? i have this code up till now but it's not working i don't know why and yet i can't separate using a ; after each row?

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";
} 

Just add a ; before the 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;
} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM