请问用C++怎么把一个字符串如:abhskansabsja里a的个数输出来?

来源:百度知道 编辑:UC知道 时间:2024/07/07 07:35:00
字符串和要查找的字符都有用户输入

#include<iostream>
#include<string>
using namespace std;
int main()
{
char a[500],*p;
gets(a);
int i=0;
p=a;
while(*p!='\0')
{
if(*p=='a')
i++;
p++;
}
cout<<i<<endl;
return 0;
}

char a[100];//用户输入字符串
for(int i=0;i<100;i++)
cin>>a[i];
cout<<"输入你要查找的字母";
char b[0];//用户比较字符串
cin>>b[0];
int m=0;//m为计数相同字符个数
if(int j=0;j<100;j++)
{
if(a[j]==b[0])
++m
}
cout<<m;
//好久没有学C++了
//你参考一下 希望没有错。。。

// alg_count_if.cpp
// compile with: /EHsc
#include <vector>
#include <algorithm>
#include <iostream>

bool greater10(int value)
{
return value >10;
}

int main()
{
using namespace std;
vector<int> v1;
vector<int&g