Search
 
SCRIPT & CODE EXAMPLE
 

CPP

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, " "));
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: matrix in vector c++ 
Cpp :: continue c++ 
Cpp :: what is c++ used for 
Cpp :: c++ get string between two characters 
Cpp :: c++ call by reference 
Cpp :: priority queue c++ 
Cpp :: console colors in C++ 
Cpp :: are strings mutable in c++ 
Cpp :: create copy constructor c++ 
Cpp :: c++ hello world 
Cpp :: how to sort in descending order in c++ 
Cpp :: continue statement in c++ program 
Cpp :: c++ initialize vector of vector with size 
Cpp :: what is a template in c++ 
Cpp :: initialize dynamic array c++ to 0 
Cpp :: bubblesort c++ 
Cpp :: input cpp 
Cpp :: c++ filesystem read directory 
Cpp :: convert 2d array to 1d c++ 
Cpp :: c detect os 
Cpp :: convert int to string in c++ 
Cpp :: sum of a matrix c++ 
Cpp :: how to know the number of a certain substring in a string in c++ 
Cpp :: c ++ splitlines 
Cpp :: c++ range based for loop 
Cpp :: structure of a function in C++ 
Cpp :: how to initialize a queue in c 
Cpp :: resize vector c++ 
Cpp :: cyclic array rotation in cpp 
Cpp :: fstream read write mode 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =