C++中count函数用法

count函数可以用来统计字符串中某个字符的个数
使用方法是count(begin,end,‘a’),其中begin指的是起始地址,end指的是结束地址,第三个参数指的是需要查找的字符。

 

#include <bits/stdc++.h>
using namespace std;

int main()
{
    string s= "abcdefgaabbccd";
    int num =count(s.begin(),s.end(),'a');
    cout<<num<<endl;
}

 

posted @ 2021-11-01 16:06  银发制御  阅读(1411)  评论(0)    收藏  举报