hi.i wanna define a vector of vector that have not certain member.actually i have two variable that show the rows and the columns and a third one that i want put them back into the rows and columns.how do it?
int no_of_columns = 5, no_of_rows = 5;
vector < vector<int> > two_d_vector(no_of_rows);
for(size_t i = 0; i < two_d_vector.size(); i++)
two_d_vector.resize(no_of_columns);
'third one that I want put them back into the rows and columns'. What? ;-;
So you have a third variable that you want to 'put back into rows and columns' what does that mean? .-.
Can you give an example or something?
Note that you should call the vector by its indexes and not with push_back() because we had resized the vector. Otherwise you would have 5x5 of 0s (in my snippet) and then whatever you pushed back.
dear Mikey boy and Grime
You're right. I made a mistake. It seems that what i tell is a 3D vector. Now again!
I wanna define a vector of vector with no certain member but your code have certain member. The rows and columns are known. I wanna the inner vector show the columns and outer vector show the rows that they have not certain member.
thanks.
That snippet's wrong. two_d_vector.resize(no_of_columns); should've been two_d_vector[i].resize(no_of_columns); sorry I'm a typo king..
I don't know what kind of 'example' you were expecting. That snippet is just for reserving space and the vector is just a regular 2d vector, so you would call it like you would have with a regular vector itself.
Anyways you should be a little familiar with vectors http://www.cplusplus.com/reference/vector/vector/ and especially their methods. If you see a method like .resize() that you're not familiar with, then Google! Don't blindly copy-paste, ask yourself what a piece of code does.
As it turns out sometimes people replying can be wrong too, like I was with that post, but you should've been familiar enough that you could've spotted the error is what I'm saying.
Anyways here's an 'example' demonstrating how 'calling 2D vectors' works.