Hi,
I would like to store binary a std::vector<std::vector<int> >
object MATRIX in a file.
out.write((char*)&MATRIX, sizeof(MATRIX));
The problem is, that only the column dimension is fixed. The row dimension changes. If I read the object out of the binary file, it's not enough to know only the size, isn't it? So, initializing e.g. a second matrix with
std::vector<std::vector<int> > MATRIX2;
for ( int i=0;i<column_dim;i++ ) MATRIX2.push_back ( vector<int> ( 0 ) );
ifstream in(cstr, ios::in | ios::binary);
and reading the object data with
ifstream in(cstr, ios::in | ios::binary);
in.read((char*)& MATRIX2, fSize);
makes no sense, because the compiler has no clue about the structure of the saved data. My question: Is there any better way of solving this problem than saving the matrix structure (all info about the row dimensions) in a second file, reading it and creating a MATRIX2 with the appropriate structure which is then filled by using
ifstream in(cstr, ios::in | ios::binary);
in.read((char*)&nn_H_test, fSize);
?