用于将容器中所有满足特定条件的元素移动到容器的末尾,并返回一个迭代器,指向新的逻辑末尾。这个函数不会真正删除元素,只是重新排列元素的位置。
前2个参数是前向迭代器,表示要处理的元素范围;第三个参数是一元谓词函数,用于判断元素是否需要被移除;
一个示例,使用std::remove_if和std::vector::erase删除所有偶数;
std::remove_if需要包含 <algorithm> ;
#include <vector>
#include <algorithm>
......
bool isEven(int );
......
void CrmifView::OnDraw(CDC* pDC)
{
CrmifDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
// TODO: 在此处为本机数据添加绘制代码
CString str1;
int col = 50, i=0;
//std::vector<int> numberList = {1, 3, 4, 7, 8, 101};
std::vector<int> numberList;
numberList.push_back(1);
numberList.push_back(3);
numberList.push_back(4);
n