开发者

How to use a "vector of vector"?

开发者 https://www.devze.com 2023-01-03 18:47 出处:网络
I already searched on the web for it but I didn\'t get satisfying results. I want to create something lik开发者_Python百科e

I already searched on the web for it but I didn't get satisfying results.

I want to create something lik开发者_Python百科e

vector< vector<int*> > test_vector;

How do i fill this vector of vector? How to access it's members? Maybe someone knows some nice tutorials on the web?

kind regards mikey


Just remember that each element of test_vector is of type vector<int*>. You would fill test_vector by filling each element vector.

You can access this just like any multi-dimensional array. See:

int *p = test_vector[0][0];

Or:

int *p = test_vector.at(0).at(0);


A question similar to yours was posted at DreamInCode: http://www.dreamincode.net/forums/topic/37527-vector-of-vectors/


You fill a vector of vectors by putting vectors in it.

You access its members the same way you would any other vector.


PS If you want to use some kind of a matrix, I would prefer to use only one dimensional vector and map the access (because of performance).

For example Matrix M with m rows and n columns: you can map call

M[i][j] = x to M[i*n+j] = x.

0

精彩评论

暂无评论...
验证码 换一张
取 消