Re: need some help with list::end ()



Hi,

Ok I'll try the *remove* method of the list and if I still cant get the
begin() method to work right I'll get back to this post.

Regards,

-ab.

"Carl Daniel [VC++ MVP]" <cpdaniel_remove_this_and_nospam@xxxxxxxxxxxxxxx>
wrote in message news:u32vT6TwGHA.3936@xxxxxxxxxxxxxxxxxxxxxxx
Abubakar wrote:
Sorry for the late reply.

How are you deleting the items? Just doing filenames.erase(filename)
invalidates the iterator to the deleted object.

I use the "remove" method.

I have the following declaration:

list<char * >::const_iterator name, prev;

at some point I do:

prev = name;
name ++;
filenames.remove ( *prev );

and this is how I remove the items.

If you have duplicates in your list, the call to remove will remove more
than one of them at a time, including possibly the one now referenced by
"name". Use the loop that Bo suggested:

if (some_condition)
filename = filenames.erase(filename);
else
++filename;

that's the canonical way to iterate through a list removing some elements
as
you go.

-cd




.



Relevant Pages

  • Re: need some help with list::end ()
    ... invalidates the iterator to the deleted object. ... I have the following declaration: ... filenames.remove (*prev); ... that's the canonical way to iterate through a list removing some elements as ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Object creation vs. ThreadLocal retrieval
    ... Object prev = null, current = null; ... Iterator it=list.iterator; ... threadlocal lookup is an orderhashmap lookup. ... public class MyThread extends Thread { ...
    (comp.lang.java.programmer)
  • Re: need some help with list::end ()
    ... invalidates the iterator to the deleted object. ... I have the following declaration: ... filenames.remove (*prev); ...
    (microsoft.public.dotnet.languages.vc)
  • Internet Explorer 6 settings
    ... minimised so I could switch between them, now if I click on a link to ... another site it opens in the same window and I cant even click back to the ... I've tried changing the IE settings but nothing has worked. ... Prev by Date: ...
    (alt.os.windows-xp)
  • Open Mail Merge from button on Access 2003
    ... will open Word and the mail merge document automaticly, and cant seem to find ... I am currently using Office 2003 with Windows XP is that changes anything ... Prev by Date: ...
    (microsoft.public.access.externaldata)