<分区>
有没有显示字符 s 在字符串中出现 5 次的函数?
#include<iostream>
#include<string>
int main(){
using namespace std;
string a="hello how are you"
//now i want to show the l character appears several time.
//and i need help here.
system("pause");
}
<分区>
有没有显示字符 s 在字符串中出现 5 次的函数?
#include<iostream>
#include<string>
int main(){
using namespace std;
string a="hello how are you"
//now i want to show the l character appears several time.
//and i need help here.
system("pause");
}
最佳答案
您可以使用 std::count
int lcount = std::count(a.begin(), a.end(), 'l');
关于c++ - 如何显示字符串中多次出现的字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19245813/