Aim : Create a vector. Use remove_if on it
#include<iostream>
#include<vector>
#include<iterator>
#include<algorithm>
#include<functional>
using namespace std;
int main()
{
int negative_count=0;
vector<int> v = { 2, -1, -3, 5, -5, 0, 7 };
copy(v.begin(), v.end(), ostream_iterator<int>(cout, " "));
cout << endl;
vector<int>::iterator new_it=remove_if(v.begin(), v.end(), bind2nd(greater<int>(), -1));
v.erase(new_it);
copy(v.begin(), v.end(), ostream_iterator<int>(cout, " "));
cout << endl;
}
The remove_if condition is to remove numbers greater than -1. Why is it displaying -5 twice?The output after remove_if should be -1 -3 -5 5 0 7 according to me. Also if i use
V.erase(new_int,v.end())
The output is fine: -1 -3 -5