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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM