vector删除元素

下面来感受下c++11之后的魔力:

#include <iostream>
#include <vector>
#include <algorithm>

int main()

{

std::vector<int>vec{ 1,2,3,4,5 };

  //vec.erase(
        //std::remove_if(vec.begin(), vec.end(), [](int value){return value == 0;}));//恭喜你程序崩溃了
   vec.erase(
       std::remove_if(vec.begin(), vec.end(), [](int value){return value == 0;}),vec.end());

}

猜你喜欢

转载自blog.csdn.net/qq_53332653/article/details/111644615