Results 1 to 6 of 6

Thread: Number of elements in a list of list

  1. #1
    Join Date
    Apr 2010
    Location
    Italia
    Posts
    149
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Number of elements in a list of list

    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
    Qt Code:
    1. std::vector< std::vector<GLdouble> > contours;
    2. ...
    3. std::vector< std::vector<GLdouble> >::iterator contour;
    4. for(contours.begin(), ite = contours.end(); contour != ite; ++contour)
    5. {
    6. for( size_t v = 0; v < ????; v += 3 )
    7. }
    To copy to clipboard, switch view to plain text mode 
    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.

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Number of elements in a list of list

    Qt Code:
    1. vector<vector<int>> lotsOfInts;
    2. // ...
    3. size_t outerVectorSize = lotsOfInts.size();
    4. size_t firstInnerVectorSize = lotsOfInts.begin()->size();
    To copy to clipboard, switch view to plain text mode 

    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.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Apr 2010
    Location
    Italia
    Posts
    149
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Number of elements in a list of list

    thanks amleto

  4. #4
    Join Date
    Apr 2010
    Location
    Italia
    Posts
    149
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Number of elements in a list of list

    KO, not good. those are the elements of contour at each iteration ?

  5. #5
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Number of elements in a list of list

    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.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  6. #6
    Join Date
    Jul 2013
    Posts
    2
    Qt products
    Qt3

    Default Re: Number of elements in a list of list

    This tips seems quite interesting and good to me.

Similar Threads

  1. Replies: 4
    Last Post: 15th June 2012, 00:33
  2. Replies: 0
    Last Post: 1st June 2011, 16:17
  3. Replies: 1
    Last Post: 23rd April 2011, 18:33
  4. List all elements of a QTreeWidget from top to bottom
    By ricardosf in forum Qt Programming
    Replies: 2
    Last Post: 12th June 2010, 03:46
  5. Algorithm for smallest number not in a list
    By zeldaknight in forum General Programming
    Replies: 4
    Last Post: 7th June 2010, 02:20

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.