且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何创建二维数组 C++?

更新时间:2021-08-24 02:43:23

我的建议是首先避免多维数组的痛苦并使用结构体.

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];

然后访问一个值:

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

不过,这完全取决于您要实现的目标.

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