# Thread: Multidimensional arrays as Matrices

1. ## Multidimensional arrays as Matrices

As I understand a multidimensional array looks like this:
Code:
```[][][][][]
[][][][][]
[][][][][]
[][][][][]
[][][][][]```
I can either have chars, integers or whatever in the array. However, I want to be able to store coordinates in this array. Something like: (2,4)

Any ideas? Or anything else I could use for this?

Code:
```   struct  coord
{
int x,y;
}

....

coord Map[12][12][12];```

3. thanks, i didn't really want to go down that line...i thought i could somehow directly add in the coordinates in a matrix like manner, since i don't read in the x and y value at the same time.

what do you mean by this: coord Map[12][12][12];

i could've done this by vector of a vector or some other combination but it has the same problem as before...

4. unfortunately the only way is to assign two types to a single location, would be by a structure, all you have to do is what Iamien sayd:

Code:
```struct coord
{
int x, y;
};

coord Map[12][12];  //no use for 3, that would be a 3d array eh...lol

//or you could do this in one statement:
struct coord
{
int x, y;
} Map[12][12];```

5. ya i dont really get this line:
coord Map[12][12];

what's the 12 for? is that the C++ assoc. container map? as in could you illustrate how you would store some coords, like (1,1), (1,2), and (1,3)

6. O the 12 would just be the size, 12 width and 12 length. So you could initialize it like so...

to initialize each coordinate point, you could go through a loop and make them all relative to their indexing numbers.

Code:
```for (int row = 0; row < 12; row++)
for (int col = 0; col < 12; col++)
{
Map[row][col].x = row;
Map[row][col].y = col;
}```
lets say you have a map called testMap and you had one coordinate on it, (0, 0) heres how you would do it:

Code:
```coord testMap;
testMap.x = 0;
testMap.y = 0;```
when you normally initialize arrays you do it like so:
Code:
`int array[2][2] = {{2, 3}, {3, 5}};`
but since its a structure you have to assign values to both x and y.

7. or you mean that MAP is a 2D array of type struct...ya i guess that's what it is...12 is the worry though...don't really know how many elements ill have...is it possible to use vectors instead...

8. ya you could use anything, vectors, list, etc... then push back the value or add it to a list.

9. oh ok...thanks a lot man...

10. hey one more thing...maybe you know this since you look fairly good at container classes...how can i store 3 values in a map...we can store pairs...i want to store this struct, an integer key and a character...i dont think multimap is the answer