C++ fill 2D array -
this question has reply here:
how declare 2d array in c++ using new? 20 answersi java programmer. i'm trying fill array in win32 project
int **data::matrixinitialize() { int** mx = new int*[n]; (int = 0; < n; i++) { (int j = 0; j < n; j++) { mx[i][j] = 1; } } homecoming mx; }
but code throw exeption. please help me fill 2d array.
you miss allocation:
int **data::matrixinitialize() { int** mx = new int*[n]; (int = 0; < n; i++) { mx[i] = new int[n]; // missing line (int j = 0; j < n; j++) { mx[i][j] = 1; } } homecoming mx; }
but improve utilize std::vector
or std::array
.
c++
No comments:
Post a Comment