Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / December 2006

Tip: Looking for answers? Try searching our database.

incrementing an STL list interator

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Abubakar - 13 Dec 2006 17:42 GMT
Hi,

lets say I have a iterator of the type:
list<string>::const_iterator itr;
lets say its at some position in a given list. Now I can goto the next item
by simply doing a itr++. But I want to increment more than just 1. Lets says
I want to increment the itr 3 times, ie being able to do something like
itr+=3. But as the += is not defined for that iterator class, I cant do
that. What should I do?

Regards,

-ab.
Doug Harrison [MVP] - 13 Dec 2006 17:48 GMT
>Hi,
>
[quoted text clipped - 5 lines]
>itr+=3. But as the += is not defined for that iterator class, I cant do
>that. What should I do?

Look into std::advance. It can handle any iterator type and will repeatedly
increment non-random access iterators as necessary. The operator isn't
provided for non-random access iterators to emphasize that increment values
> 1 aren't as simple and efficient as pointer arithmetic.

Signature

Doug Harrison
Visual C++ MVP

Abubakar - 13 Dec 2006 17:59 GMT
Wow, pretty cool. Thanks :)

-ab.

>>Hi,
>>
[quoted text clipped - 14 lines]
> values
>> 1 aren't as simple and efficient as pointer arithmetic.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.