Vector question

if I have a vector like this vector<int>arr[100];

does this mean that each vector element is an array ? or does it mean that each element in the array has its own vector? like a[0] has a vector a[1] has another vector and so on just like an array of arrays?
this is an array of vectors. This isnt something you would ever DO without a really odd requirement or reason, you would do a double vector
vector<vector<int> > arr;

so arr[0].length() or arr[0].push_back(3.14); is what you are dealing with.

It is like an array of arrays. Actually, its ugly under the hood, but

arr[0][1] = 10; //this is ok, as long as the vector has been reserved/pushbacked to allow it.


@jonnin needed it in a graph representation of an adjacent list, but thanks jon!
You are welcome. I can't see anything you can do with the array that you can't do with the double vector, no matter what it represents, they are functionally about the same apart from having to manhandle the vector memory if you don't load with push. It will work either way, its just a bit odd.
Last edited on
Topic archived. No new replies allowed.