How to define a 2D array in C++ and STL without memory manipulation?

后端 未结 8 1570
隐瞒了意图╮
隐瞒了意图╮ 2021-02-06 03:14

There are several ways to define a 2D array in C++ and STL without memory manipulation, and the following codes illustrate two different methods:

int main () 
{
         


        
8条回答
  •  一个人的身影
    2021-02-06 03:45

    One very efficient method to define arrays is dynamic allocation, using the new and delete operators. Here is an example:

    int **arr=new int*[ROW];
    for( int i=0; i

    The big advantage of this approach is that when you don't need any more the memory that the array uses, you can easily delete it. Here is an example of deleting a 2D array:

    for( int i=0; i

提交回复
热议问题