# How do I create a multidimensional Vector?

This topic is 5469 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Can someone show me how to create a vector with the dimensions ROW, COL (will end up as 15, 20) that can be accessable by myvector[row][col]? I need it to work like this: 1. The vector is declared in the object 2. In the constructor, the vector is given it's sizes. 3. Later, the vectors values are set using a loop (They'll be read from a file) that works like loop i { loop j { myvector[j] = something; } } (Too lazy to write the C++ code)

##### Share on other sites
vector of vectors:
typedef vector< vector<Type> > Type2DArray;

##### Share on other sites
That doesn't really help me in setting the size and such.

##### Share on other sites
Just goes to show Oluseyi, you can lead a horse to water...

std::vector<std::vector<int> > myvec(15, std::vector<int>(20));

##### Share on other sites
I believe the following will work:

Class definition:

std::vector< std::vector< int > > m_vector;

Initialization list:

m_vector(20, std::vector< int >::vector(30, 0))

That'll give you [20][30] sized, with all values initially set to 0.

Edit: Too late, what he ^ said. Mine is wrong anyway.

##### Share on other sites
Damn this STL stuff, I'm completely new to it, so I don't understand half of it (Except string functions, I love them)

Is there any form of book on it?

##### Share on other sites
Why yes! There is!
Books.VirtuallyOnline.Net

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 15
• 22
• 17
• 46