View Full Version : iterator
mickey
21st May 2006, 16:33
I'd like to convert iterator to int without using map. is it possible?
vector<boj>::iterator ll;
//int i=1;
for (ll=boj.begin(); ll != boj.end(); ++ll)
printf("boj number %i\n",
// i++ I'd like to avoid this way. I don't like
And why use '++ll' in for and not 'll++'? Thanks
jacek
21st May 2006, 16:38
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.
wysota
21st May 2006, 17:28
And for some iterators postfix ++ operator is not defined.
mickey
21st May 2006, 18:07
thanks a lot! But the first part of my post have answer? Thanks
jacek
21st May 2006, 18:36
But the first part of my post have answer?
Didn't you ask that question earlier?
mickey
21st May 2006, 20:07
It was similar...
int i = abs(obj.begin() - ll);
I hope this is good......
mcosta
23rd May 2006, 11:28
It was similar...
int i = abs(obj.begin() - ll);
I hope this is good......
The correct way is
int i = distance(obj.begin(), ll);
Powered by vBulletin® Version 4.2.5 Copyright © 2023 vBulletin Solutions Inc. All rights reserved.