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>::iterator itr = srcVector; itr != srcVector; itr++) {
int i = (*itr);
// if i contains in destVector, remove that from both srcVector
and destVector
for (vector<int>::iterator itr = srcVector.begin();
itr != srcVector.end(); ) {
vector<int>::iterator posDest
= std::find (destVector.begin(), destVector.end(), *itr)
if (posDest != destVector.end()) {
srcVector.remove (itr);
destVector.remove (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