Hi,
I have a matrix of size of n x m, how can the file be read without any given size, thus making it possible to be read with any given size matrix?. Here is the scenario, I have a matrix of size 3 x 2 then someone wants to use use my program and he has a file with say matrix of size of 8 x 10...the program should handle any matrix size.

Pop a headder struct at the top of the file which is of sixed size. It would contain file size data.

i would suggest a struct something like.

struct MatrixFileHeadderInfoVer1_st
{
    int m_nVersion; //file headder version

    int m_nMatrixColumns;
    int m_nMatricRows;
};

With something like you can later update the file headder with more information as and when needed. Then copy the data into the correct struct type to read all the data from the file correctly.

Might not be exactly what your looking for but i think its a good way to go.

Could the dimensions of the matrix not be included in the file itself? That is what I usually do. The very first entries of the file are the dimensions of the matrix, say, 8 10
The rest of the file contains the matrix entries themselves.
However you do it, you are going to end up using dynamic arrays to size the arrays during program execution.

Nope... C++ doesnt support that... When reading data from a file, which once had data written into it using a matrix(arrays) , structures or classes, their definitions have to be stuck to... So, u cant read a file i wrote using 2 variables of int in a class, by using a class which has 4 variables of char... The definition HAS to remain the same...

As far as i know, its not possible doing what u came up with, though if u do happen to come across it, please pm me telling me bout the same....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.