Horje
c++ remove numbers from vector if larger than n Code Example
c++ remove numbers from vector if larger than n
#include <vector>
#include <algorithm>
#include <iostream>
#include <iterator>
using namespace std;

int main()
{
  // intitalize both the vector and the target value to be under
  vector<int> V = {2,3,5,11};
  int target = 8;
  
  // remove any numbers in the vector that is larger than the target
  vector<int> :: iterator it = remove_if(V.begin(), V.end(), bind2nd(greater<int>(), target));
  V.erase (it, V.end());
  
  // output the answer
  copy(V.begin(), V.end(), ostream_iterator<int>(cout, " "));
}




Cpp

Related
how to check size of file in c++ Code Example how to check size of file in c++ Code Example
c++ vector fill Code Example c++ vector fill Code Example
round double to 2 decimal places c++ Code Example round double to 2 decimal places c++ Code Example
precision of fixed in c++ Code Example precision of fixed in c++ Code Example
c++ functions inside functions Code Example c++ functions inside functions Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
9