// count_if.cpp -- 2011-10-02-22.16
#include "stdafx.h"
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
using std ::vector ;
using std ::equal_to ;
int _tmain(int argc, _TCHAR* argv[])
{
int arr1[] = {1, 2, 3, 4, 5, 1, 8, 9} ;
vector<int> vec1(arr1, arr1 + sizeof arr1 / sizeof (int)) ;
// count_if (beg, end, unaryPred) ;
// 操作前:[beg,end)标示输入序列.unaryPred是一元函数对象.
// 操作后:确定输入序列中使unaryPred返回true的元素的个数.
// 返回值:使unaryPred返回true的元素的个数
// 备注: 无.
size_t iCount = count_if(vec1.begin(), vec1.end(), bind1st(equal_to<int> (), 1)) ;
std ::cout << iCount << std ::endl ;
std ::cin.get() ;
return 0 ;
}
count_if
最新推荐文章于 2022-09-22 22:41:30 发布