// test_matrix.cpp dynamic matrix, just vector of vectors #include #include using namespace std; int main() { typedef vector d_vec; typedef vector d_mat; d_mat mat; // dynamic size matrix, initially 0 by 0 d_vec row; cout << "test_matrix.cpp" << endl; row.push_back(1.0); row.push_back(2.0); row.push_back(3.0); // build the first row mat.push_back(row); row[0]=4.0; mat.push_back(row); row[1]=5.0; mat.push_back(row); // now have 3 by 3 1.0 2.0 3.0 // 4.0 2.0 3.0 // 4.0 5.0 3.0 cout << "mat[2][2]=" << mat[2][2] << endl; mat[1][1]=9.0; mat[0].push_back(4.0); mat[1].push_back(6.0); mat[2].push_back(7.0); row.push_back(8.0); mat.push_back(row); // now have 4 by 4 1.0 2.0 3.0 4.0 // 4.0 9.0 3.0 6.0 // 4.0 5.0 3.0 7.0 // 4.0 5.0 3.0 8.0 cout << "mat[2][3]=" << mat[2][3] << endl; mat[2][3]=7.0001; // obviously do not use mat[4][4], it does not exists for(int i=0; i