C++中关于count的用法总结

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;
posted @ 2022-11-08 09:49  笑着的程序员  阅读(373)  评论(0)    收藏  举报  来源