Results 1 to 7 of 7

Thread: iterator

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default iterator

    I'd like to convert iterator to int without using map. is it possible?
    Qt Code:
    1. vector<boj>::iterator ll;
    2. //int i=1;
    3. for (ll=boj.begin(); ll != boj.end(); ++ll)
    4. printf("boj number %i\n",
    5. // i++ I'd like to avoid this way. I don't like
    To copy to clipboard, switch view to plain text mode 

    And why use '++ll' in for and not 'll++'? Thanks
    Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: iterator

    Quote Originally Posted by mickey
    why use '++ll' in for and not 'll++'? Thanks
    ll++ is less effective, because it must create a copy of the iterator, increment the iterator and return that copy.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: iterator

    And for some iterators postfix ++ operator is not defined.

  4. #4
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: iterator

    thanks a lot! But the first part of my post have answer? Thanks
    Regards

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: iterator

    Quote Originally Posted by mickey
    But the first part of my post have answer?
    Didn't you ask that question earlier?

  6. #6
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: iterator

    It was similar...
    Qt Code:
    1. int i = abs(obj.begin() - ll);
    To copy to clipboard, switch view to plain text mode 
    I hope this is good......
    Regards

  7. #7
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: iterator

    Quote Originally Posted by mickey
    It was similar...
    Qt Code:
    1. int i = abs(obj.begin() - ll);
    To copy to clipboard, switch view to plain text mode 
    I hope this is good......
    The correct way is

    Qt Code:
    1. int i = distance(obj.begin(), ll);
    To copy to clipboard, switch view to plain text mode 
    A camel can go 14 days without drink,
    I can't!!!

Similar Threads

  1. pointer and iterator
    By mickey in forum General Programming
    Replies: 6
    Last Post: 3rd February 2008, 22:24
  2. QLinkedList iterator
    By ^NyAw^ in forum Qt Programming
    Replies: 8
    Last Post: 18th October 2007, 16:15
  3. Std iterator as private member variable
    By Michiel in forum General Programming
    Replies: 5
    Last Post: 21st April 2006, 15:27
  4. ::iterator
    By mickey in forum General Programming
    Replies: 2
    Last Post: 20th March 2006, 22:05
  5. convert iterator
    By mickey in forum General Programming
    Replies: 8
    Last Post: 20th March 2006, 21:59

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.