Matrices

I am writing a code for a matrix calculator,

I am reading the elements of a 3x3 matrix from a text file but how do I then use these in my coding?
1
2
3
4
5
6
double matrix[3][3];
ifstream fin("input.txt");

for (int i = 0; i < 3; ++i)
    for (int j = 0; j < 3; ++j)
        fin >> matrix[i][j];


Now just refer to matrix[i][j] when looking at an element. If you want a matrix to have more than 2 dimensions, or if you want anything but a 3x3 matrix, check out dynamic memory allocation or STL containers.
another options is
std::vector < std::vector <_type_def> > matrix;
or
std::map<type_def, type_def> matrix;
both are dynamically allocated.
Topic archived. No new replies allowed.