1. count()的调用接口
template<class InputIterator, class Type>
typename iterator_traits<InputIterator>::difference_type count(
InputIterator _First,
InputIterator _Last,
const Type& _Val
);
2. 模拟实现原理
#include<iostream>
using namespace std;
int mycount(int* pStart,int* pEnd,int value){
int n = 0;
while (pStart != pEnd){
if (*pStart == value){
n++;
}
pStart++;
}
return n;
}
int main(){
int arr[] = {3,2,7,5}; //容器
int* pStart = arr;
int* pEnd = &arr[sizeof(arr)/sizeof(int)];
int n = mycount(pStart, pEnd,2);
cout << "n:" << n << endl;
system("pause");
return EXIT_SUCCESS;
}