remove配合erase使用,remove会删除所有的需要删除的元素,但会把删除的元素保存在最后一位。比如vector{1,2,3,1,2},删除1,后会变成vector{2,3,2,1},所以还需要erase删除最后一位元素,才能彻底删除干净
#include#include using namespace std; int main() { vector num{ 1,5,6,8,4,9,3,5,4,7,6,1,5,6,8,1,2,3 }; std::cout << "num size is :"< function函数和bind的结合使用,bind用placeholders::_1占位符来表示参数的位置,bind的思想实际上是一种延迟计算的思想,将可调用对象保存起来,然后在需要的时候再调用。
#include#include #include using namespace std; bool test(int a, int b) { return a < b; } int main() { function fun = bind(test, placeholders::_1, 10); bool data = fun(5); cout << data << endl; } replace_if主要是做替换,比如想将元素中的某个元素全部替换成a,可以采用这方法
#include#include #include #include using namespace std; int main() { vector num{ 1,2,3,6,5,1,4,7,5,1,6,4,2,3 }; replace_if(num.begin(), num.end(), [](int data) {return data == 1; }, 10); for (size_t i = 0; i < num.size(); i++) { cout << num[i]<<"t"; } }



