Sign in to follow this  

How do I create a multidimensional Vector?

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

If you intended to correct an error in the post then please contact us.

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[i][j] = something; } } (Too lazy to write the C++ code)

Share this post


Link to post
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 this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this