Jump to content
  • Advertisement
Sign in to follow this  
Geno the Great

How do I create a multidimensional Vector?

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

Share this post


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


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

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!