C++中关于count的用法总结
下面是关于字符串中count的两种用法,STL容器,数组的用法类似
#include <iostream>
#include <string>
#include <algorithm> //count
using namespace std;
int main()
{
string m = "1233445";
//int n = count(m.data(), m.data()+m.size(),'3');
int n = count(m.begin(), m.end(),'3');
cout << n << endl;
return 0;
}
//vector用法:
cout << count(v.begin(), v.end(), 6) << endl;
//数组用法:
cout << count(a, a + 10, 4) << endl;