Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How create dynamically new 2D array in C++

As in the subject how create new 2D array in C++? This code below does not work quite well.

int** t = new *int[3];
for(int i = 0; i < 3; i++)
       t[i] = new int[5];
like image 573
Yoda Avatar asked Dec 27 '22 10:12

Yoda


2 Answers

You have a * in the wrong spot. Try:

int **t = new int *[3];
like image 146
Carl Norum Avatar answered Dec 29 '22 01:12

Carl Norum


Would vector< vector< int > > work?

like image 41
strannik Avatar answered Dec 29 '22 01:12

strannik