Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have written a program which calculates matrices. Now I want to use those calculated matrices. So I want my C++ programm to generate a file on my computer and to copy the calculated matrix to this new file. Does anybody know how to do this?

Have you tried using a map of vectors?
map being your columns and the vector holding data for each column

#include<stdio.h>
int mat[3][3] = {{1, 2, 3},
{4,5,6},{7,8,9}};
main()
{
int i, j;
mat2[3][3];/*Write matrix to file*/
FILE *fp = fopen("matrix.txt", "w");
for(i=0; i<3; i++)
for(j=0;j<3; j++)
fprinf(fp, "%d\n", mat[i][j]);
fclose(fp);/*Read matrix back from file*/
fp = fopen("matrix.txt", "r");
for(i=0; i<3; i++)
for(j=0;j<3; j++)
fscanf(fp, "%d", &mat2[i][j]);
fclose(fp);
}Santanu Sen
National Institute of Technology
Durgapur
India

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |