c++ vector删除元素,使用unique ,erase

//
// Created by wuyongyu on 2019-10-10.
//

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std::chrono_literals; // for sleep_for(10s)
using namespace std;

int main() {
  std::vector numbers{1,2,2,3,4,4,7,8};

  std::vector::iterator a= std::unique(numbers.begin(), numbers.end(), [](const int& a,
      const int& b) {
      return a ==b;
  });
  numbers.erase(a, numbers.end());

  cout << numbers.size();
  return 0;
}

你可能感兴趣的:(c-c++)