统计字符串中每个字符出现的次数

2014-11-23 22:19:29 · 作者: · 浏览: 5
1#include
2#include
3using namespace std;
4
5int main(){
6 string str;
7 int ascii[256]={};
8 cout<<"请输入一个字符串:";
9 getline(cin,str);
10 for(int i=0; i11 ascii[(int)str[i]]++;
12 for(int i=0; i<256; i++)
13 if(ascii[i]!=0)
14 cout<<(char)i<<"出现:"<15}