std::remove does not change the size of the container,it moves elements forward to fill gaps created and returns the new 'end' position. : remove « STL Algorithms Modifying sequence operations « C++ Tutorial






#include <algorithm>
#include <vector>
#include <list>
#include <iostream>

using namespace std;

int main (){
    list <int> l;

    for (int nCount = 0; nCount < 10; ++ nCount)
        l.push_back (nCount);

    list <int>::const_iterator li;
    for ( li = l.begin (); li != l.end (); ++ li )
        cout << *li << ' ';

    vector <int> v (l.size () * 2);

    vector <int>::iterator iLastPos;
    iLastPos = copy ( l.begin (), l.end (), v.begin () );

    vector <int>::iterator i;
    i = remove (v.begin (), v.end (), 0);

    v.erase (i , v.end ());
    vector <int>::iterator vi;
    for ( vi = v.begin (); vi != v.end (); ++ vi )
        cout << *vi << ' ';

    return 0;
}








24.8.remove
24.8.1.Use the generic remove algorithm
24.8.2.Use std::remove to delete all element in a vector by value
24.8.3.Remove an element and then erase that element
24.8.4.Combine remove and erase together
24.8.5.Use remove() to delete elements from a vector
24.8.6.std::remove does not change the size of the container,it moves elements forward to fill gaps created and returns the new 'end' position.
24.8.7.Remove value from a vector with remove()