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; }

浙公网安备 33010602011771号