I wanted to create a three dimensional array in the following code but i get run time error.
int dim1,dim2,dim3;
std::cout<<"dim one\n";
std::cin>>dim1;
std::cout<<"dim two\n";
std::cin>>dim2;
std::cout<<"dim three\n";
std::cin>>dim3;
int ***three_dim=0;
three_dim=new int**[dim1];
for(int i=0;i<dim1;++i)
three_dim[i]=new int*[dim2];
for(int k=0;k<dim2;++k)
three_dim[k]=new int*[dim3];
for(int k=0;k<dim1;++k)
for(int i=0;i<dim2;++i)
for(int j=0;j<dim3;++j)
three_dim[k][i][j]=0;
EDIT:
it is a must that i use a three dimensional array. I have created a two dimensional array with the same style and wanted to extend it to three because that is what i need. But as you can see i got confused.
Thank you Bo Persson
This part
has two problems. One is that is allocates
int*instead ofint. The other, more serious, is that it overwrites the previously allocated pointers from the lines above.You should probably do the allocation like this: