开发者

How to use a "vector of vector"?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜