Removing elements from vector using remove_if

Multi tool use
Multi tool use
The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Removing elements from vector using remove_if



I am trying to remove vector elements using remove_if. But unsuccessfully. What am I doing wrong?


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
void printme(std::vector<int>& a){
for(const auto& item: a)
std::cout << item << std::endl;
}
int main()
{
std::vector<int> a {1, 2, 3, 4, 5, 6};
printme(a);
a.erase( (std::remove_if(a.begin(), a.end(), (const int& x){
return x == 2;
}), a.end()));
printme(a);
}



My output is just: 1 2 3 4 5 6



Expected output: 1 2 3 4 5 6 1 3 4 5 6









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

f5yeEQk8OnWYxtvzn,UCe,zME IzxopsQ 8D7N5Wd
EWGH A9H N,frrqIdFJ 1x7b2GQzPPE My

Popular posts from this blog

Visual Studio Code: How to configure includePath for better IntelliSense results

Spring cloud config client Could not locate PropertySource

Current 93