count_if

来源:互联网 发布:我的淘宝网登陆 编辑:程序博客网 时间:2024/04/20 02:17
 
// 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 ;}
原创粉丝点击