Pointer to vector of vectors

Hi
I'm trying to write a code that have vector and this vector holds another vectors and i cant find out how to push vectors into this "array" of vectors
my code looks like this:

1
2
3
4
5
6
7
vector<vector<int> > *varVect;
 //this is the vector pointer that need to hold the other vectors

vector<int> var;   
//i creates on loop this vector with values 
//and every time its full i need to insert it to the array of vectors


the vector<int> var works fine,after i insert values i print it and its ok
but when i try to insert it to the other vector and the trying to print all the list of vectors its not working
i need to know how can i insert a vector to list of vectors properly and how to work in vectors in the list

1
2
3
4
5
6
7
8
9
10
11
12
for(int j=0;j<varDim;j++){
instr >> num;  //enter some numbers to the vector
var.push_back(num);
}
varVect[i].push_back(var); //this is how i enter the vector to the list of vectors

//this is my print function (work good on vector<int> var
void fileHandling::printVector(vector<int>& vec){
	for (vector<int>::size_type i = 0; i < vec.size(); i++)
		cout<<vec[i]<<" ";
	cout<<"\n";
}


thank you for your help!
Last edited on
You probably mean:
 
vector<vector<int> > varVect;  // * removed 

This ought to be your code:
 
varVect[i].push_back(var); //this is how i enter the vector to the list of vectors 
Last edited on
Hi
thank for your help
i need it to be pointer.
i tried your advice its worked but without the [ i ] only varVect.push_back(var)

i will try to do this with pointers
Last edited on
why do you need it to be a pointer? You will then have to allocate memory dynamically using 'new' and be careful of avoiding memory leaks.

instead just modify your code and try
 
varVect.push_back(var); // remove [i] 
It's Ok guys
all working fine
thank you
Topic archived. No new replies allowed.