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; }
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刪除。