View Full Version : iterator
mickey
21st May 2006, 15: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, 15: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, 16:28
And for some iterators postfix ++ operator is not defined.
mickey
21st May 2006, 17:07
thanks a lot! But the first part of my post have answer? Thanks
jacek
21st May 2006, 17:36
But the first part of my post have answer?
Didn't you ask that question earlier?
mickey
21st May 2006, 19:07
It was similar...
int i = abs(obj.begin() - ll);
I hope this is good......
mcosta
23rd May 2006, 10: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 © 2024 vBulletin Solutions Inc. All rights reserved.