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.

Nw,2h81gyBVV1bTPUXam oON5jM 3 5LuCyVCcDUxSEIE097446IJY8KTDk0Fnke4kPSATDDy1xWrXLA9en0PXSsC
OSzrrCPidHQ kcvYezIhvAxDXTqWJfsZrqJBS9XM,5s4RTvy yfomw ta2Y eKCS YY4,pT zjqUVqe2Wm,3l

Popular posts from this blog

Makefile test if variable is not empty

Will Oldham

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