How do I create a multidimensional Vector?
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)
Just goes to show Oluseyi, you can lead a horse to water...
std::vector<std::vector<int> > myvec(15, std::vector<int>(20));
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement