abort remove_if of vector
来源:互联网 发布:爱五子棋打谱软件 编辑:程序博客网 时间:2024/06/18 04:57
今天在使用remove_if函数来删除指定的vector元素的时候,发现虽然vector容器中指定的元素被删除了,但是vector容器的大小并没有变,打印出所有的元素发现,vector中未被删除的元素都向前移动了,移动之后,没有元素的位置上默认填充vector中最后的元素值,例如:
code
#include<iostream>using namespace std;#include<vector>#include<algorithm>template <typename T>class Display{ public: void operator()(const T& x) { cout << x <<" "; }};template <typename T>class Equal{ public: T m_x; Equal(const T& ix) { m_x = ix; } bool operator(const T& x) { retrun m_x == x; }};int main(int argc,char* argv[]){ int arr[] = {1,2,3,4,5}; vector<int> iv(arr,arr+5); cout << " Before removed: "; for_each(iv.begin(),iv.end(),Display()); remove_if(iv,begin(),iv.end(),Equal(3)); cout << "After removed: "; for_each(iv.begin(),iv.end(),Display()); return 0;}
result
Before removed: 1 2 3 4 5 After removed: 1 2 4 5 5
0 0
- abort remove_if of vector
- vector remove_if
- remove_if
- remove_if
- remove_if
- remove_if
- 调bug:terminating with uncaught exception of type std::out_of_range: vector Abort trap: 6
- STL中remove_if()/find_if()/replace_if()的使用方法(The usages of remove_if()/find_if()/replace_if() )
- abort
- abort
- abort
- 为什么vector的remove_if实际上并没有删除元素,而要配合erase使用
- C++/STL_利用remove_if 删除vector,list,deque满足条件的元素
- 关于remove_if
- remove_if用法
- remove_if用法
- remove remove_if
- std::remove_if
- HDU5706 GirlCat
- 从如何提升自己开始吧
- 面对用户的需求设计
- Tiny_cnn用自己的数据训练和测试
- 基础算法之冒泡排序
- abort remove_if of vector
- C++卷积神经网络实例:tiny_cnn代码详解(2)——代码试运行
- http session
- 《众病之王-癌症传》
- Random Forest 实用经验(转)
- TCP /IP 协议-(传输层)TCP 协议
- 糖果机器人_0001_简单的界面设计
- 50道编程小题目
- 配置跟踪开关