tags:

views:

163

answers:

4

Hi!

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

I want to create something like

vector< vector<int*> > test_vector;

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

kind regards mikey

+1  A: 

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

Kyra
+2  A: 

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);
Ben Collins
Thanks! I reconsidered the problem and in order I wrote some test programms which helped me in my understanding!
Mike Dooley
+1  A: 

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.

LonliLokli
This assumes the OP wants each of the interior vectors to be the same size... which may not be the problem at hand.
andand
Therefore I use Matrix in my answer.
LonliLokli
+1  A: 

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

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

Noah Roberts