1. count算法用于计算容器中的某个给定值的出现次数。
2. count_if算法是统计迭代器区间[first , last)上满足条件的元素个数n,按计数n是否引用返回
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int fun(int &i){
return i%2 ? 0:1;
}
int main(){
vector<int> v1 = {2,3,2,3,4,5,2,3};
auto res = count(v1.begin(),v1.end(),2);
cout<<res<<endl;
auto res1 =count_if(v1.begin() , v1.end() ,fun);
cout<<res1<<endl;
}
~