Multidimensional array data storage

I want to store an 80x80 array where each array will have 3 integer values. Nay Idea on how to get this done?
I've been trying to no success
So, you want 80x80x3 values total? Probably easiest to use a struct (with a meaningful name).

1
2
3
4
5
6
7
8
9
10
11
12
struct Color {
    int r;
    int g;
    int b;
};

int main()
{
    Color arr[80][80] {};
    
    arr[0][1].r = 42;
}
its 3d.
int thing[rows][cols][3];

you can enum the meaningful name:
enum {one, two, three};
thing[somerow][thiscolumn][three];

the enum values are off by one from their english name here, but its just a dumb example :)
Last edited on
Another potential solution may be to use an STL vector coupled with a pair of one value and a pair of two values.

Consider the following declaration:
vector<pair<T1, pair<T2, T3>>> v[N][M];

You can access your values that way:
1
2
3
v[x][y].first; // value one
v[x][y].second.first; // value two
v[x][y].second.second; // value three 
Registered users can post here. Sign in or register to post.