Remove value from a vector with remove() : remove « STL Algorithms Modifying sequence operations « C++ Tutorial






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

using namespace std;

bool greater9( int );

int main()
{ 
   const int SIZE = 10;
   int a[ SIZE ] = { 10, 2, 10, 4, 16, 6, 14, 8, 12, 10 };

   // Remove 10 from v
   vector< int > v( a, a + SIZE );
   vector< int >::iterator newLastElement;
   newLastElement = remove( v.begin(), v.end(), 10 );

   return 0;
}

bool greater9( int x )
{
   return x > 9;
}








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()