STL iterator delete problem

wangzh3發表於2008-02-19

years ago carl report problem in chinaunix.net: bug of stl on hpux.when delete some element in the stl containers,not work.others ok.

now i encount the problem again,but not bug.and the solution:

for(iterator continue)

{

if(want to delete)

{

delete the pointer;

delete the element and move on the cursor;

}

else

{

increment

}

}

and use the r iterator also will be ok.just because when you delete the elemetn.so the iteraotr changed,then error occurs

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/47869/viewspace-999701/,如需轉載,請註明出處,否則將追究法律責任。

相關文章