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