Re: removing multiple values in a set



"kunal s patel" <kunalspatel@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
message news:B13BAAFF-6E24-470B-85B7-AC31283B690B@xxxxxxxxxxxxx
I have a set which contains a bunch of ip address. Now my application
tries to connect to that ip address and if the connection fails then
it removes that ip address from the set("stale ip")......Now how do i
achieve this???

Here is the loop

set<CString>::iterator itr = remotenodeip.begin();

while(itr != remotenodeip.end())
{
CString ip_addr = *itr;
CString result = PeerLookup(ip_addr);

if(result.Compare("Error")==0)
{

//Remove that ip address from the set

}
itr++;
}

if(result.Compare("Error")==0) {
remotenodeip.erase(itr++); // must use post-increment
} else {
++itr; // slightly more efficient to use pre-increment
}

--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


.



Relevant Pages

  • Re: Avoiding Overflow
    ... land, and it could be dangerous sitting under them as they fly ... overhead. ... -- RFC 1925 ...
    (microsoft.public.vc.language)
  • Re: Muliple framed webpage scroll position
    ... and it could be dangerous sitting under them as they fly ... overhead. ... -- RFC 1925 ... Prev by Date: ...
    (microsoft.public.inetsdk.programming.webbrowser_ctl)
  • Re: fatal error C1083: Cannot open include file
    ... land, and it could be dangerous sitting under them as they fly ... overhead. ... -- RFC 1925 ...
    (microsoft.public.vc.language)
  • Re: Printing to the printer
    ... and it could be dangerous sitting under them as they fly ... overhead. ... -- RFC 1925 ... Prev by Date: ...
    (microsoft.public.vc.language)
  • Re: IE Sychost.exe.Application Error
    ... land, and it could be dangerous sitting under them as they fly ... overhead. ... -- RFC 1925 ...
    (microsoft.public.inetsdk.programming.webbrowser_ctl)

Loading