many numerical software and libraries handle multidimensional arrays as a single dimension array. i don’t know why but i don’t like to write
so i resort to using multidimensional versions of stl containers. i wonder why it is not used.
this is how i store a matrix with 4 rows and 3 columns.
// declaration and memory allocation done together std::vector <std::vector <double > > matrix(4, std::vector<double>(3));
that creates a vector of vector.
however one can also resize the vector later after an initial declaration. up until now i only resized one-dimensional vectors but here is how one can resize multi-dimensional vectors.
// declaration alone std::vector <std::vector<double> > matrix; // blah blah // // // now for memory allocation matrix.resize(4, std::vector<double>(3));