c++ - 如何显示字符串中多次出现的字符?

标签 c++ string

<分区>

有没有显示字符 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/

相关文章:

c++ - 如何强制 xcode 使用正确的 iostream header C++

Python - 解析字符串,已知结构

python - 按照特定模式从列中提取字符串

c - 使用字符串的基于堆栈的缓冲区溢出异常

c++ - 如何让我的私有(private)类对 STD 容器可见?

c++ - 在 CentOS 5.11 中运行 libcurl7.43.0 make 时出错

c++ - 从 std::list 中清除元素的顺序是什么?

c++ - 即使使用 ios::binary 也无法以二进制模式写入文件

string - 如何找到字典序最小的字符串旋转数?

python - 字符串到 np.matrix 返回字符串