Number of vectors in a vector of vectors?

I have a 2d vector that is not necessarily square. I want to know how many rows and columns it has (obviously, it isn't really 2d, but I'm thinking of it as an array).

The number of elements of each vector within this vector can be found with vec[i].size(), but what about the number of vector elements within the original vector? Can I use vec.size()? Or will that return the total number of elements in the 2d vector?

Try it, see what happens. It should be pretty easy.
Yes you can use vec.size() to determine how many "rows" the vector has.

For example you can count the total number of elements the following way (assuming that you have std::vecror<vector<int>>)

std::vector<vector<int>>::size_type total = 0;
for ( const auto &v : vec ) total += v.size();
I was hoping the OP could figure that out himself.

I think one can learn more by testing their own theories, rather than just getting the answer from someone.

I am not trying to offend anyone, just my Opinion :+) Cheers
Went with what I said in the OP and everything worked out, thanks all the same.
Topic archived. No new replies allowed.