On 5 Mar 2006 09:20:48 -0800, in comp.lang.c++ you wrote:
How can I emove an item in STL iterator without use the STL algorithm?
I know we can use stl erase, find_if to remove items from a STL vector
, but how can I do the same without using STL algorithm?
vector<int> srcVector;
vector<int> destVector;
for (vector<int>::i terator itr = srcVector; itr != srcVector; itr++) {
int i = (*itr);
// if i contains in destVector, remove that from both srcVector
and destVector
for (vector<int>::i terator itr = srcVector.begin ();
itr != srcVector.end() ; ) {
vector<int>::it erator posDest
= std::find (destVector.beg in(), destVector.end( ), *itr)
if (posDest != destVector.end( )) {
srcVector.remov e (itr);
destVector.remo ve (posDest);
} else {
++itr;
}
}
Not tested. Does not work for duplicate entries in srcVector or
destVector. Replace 'std::find' with your own 'find' function if you
don't want std::algorithms .
Best wishes,
Roland Pibinger