How to create 2d array c++?

后端 未结 5 2063
无人共我
无人共我 2020-12-10 21:05

I need to create 2d array in c++.

I can\'t do it by int mas= new int[x][y]; or auto mas= new int[x][y]; I need to create an array dynamical

5条回答
  •  隐瞒了意图╮
    2020-12-10 21:19

    My advice would be to avoid the pain of multidimensional arrays in the first place and use a struct.

    struct Point {
        int x;
        int y;
    }
    
    int points = 10;
    Point myArray[points];
    

    Then to access a value:

    printf("x: %d, y: %d", myArray[2].x, myArray[2].y);
    

    Depends on exactly what you're trying to achieve, though.

提交回复
热议问题