Array of vectors

If you want to make an array of vectors while reading it’s size from a file you have to do this:

int size;
in>>size;
vector<A>[size] vector_array;

I’m not sure what you want. If you want to read it’s value from a file you can do this:

for(int i = 0;i<array.size();i++){
   //get data from file and convert it to the object you want
   vector_array[i] = generated_object;
}

If you want to copy vectors from an array to another vector array you can use this:

for(int i = 0;i<size_of_array_to_copy;i++){
    vector_array[i] = array_to_copy[i];
}    

Yes, it will look like a tree, a vector of vectors looks like a tree too.
The fact that you’re in a class constructor or that you will call one in the future doesn’t change anything. It doesn’t matter you’re using a struct, structs and classes are similar.
You should just use vectors, they are just arrays with a dynamic size.

Leave a Comment