PDA

View Full Version : Number of elements in a list of list



giorgik
1st May 2013, 12:37
Hello everyone, I have a problem like this: I do not know how to count the number of elements in a list of lists. Let me explain:
I have the following list of list


std::vector< std::vector<GLdouble> > contours;
...
std::vector< std::vector<GLdouble> >::iterator contour;
for(contours.begin(), ite = contours.end(); contour != ite; ++contour)
{
for( size_t v = 0; v < ????; v += 3 )
}

I do not know how to write the part indicated with ???? that represents the size (ie the number of elements of the list std::vector<GLdouble>).
Can you help me, I'm going crazy.

amleto
1st May 2013, 13:01
vector<vector<int>> lotsOfInts;
// ...
size_t outerVectorSize = lotsOfInts.size();
size_t firstInnerVectorSize = lotsOfInts.begin()->size();


hope you can figure it out from that.

This is trivial c++ and definitely not Qt programming specific. Please consider better which forum you ask these questions in.

giorgik
1st May 2013, 16:48
thanks amleto

giorgik
1st May 2013, 19:39
KO, not good. those are the elements of contour at each iteration ?

amleto
1st May 2013, 21:27
please get acquainted with online references. Here is a good start:
http://www.cplusplus.com/reference/vector/vector/

This is not a forum to teach c++ to beginners.

saim45
18th July 2013, 08:36
This tips seems quite interesting and good to me.