int main() { char *str="aabcaadeegfssdjfekfajfbewf"; int cout_array[256]={0}; //遍历每个字符,将每个字符作为cout_array的index,即直接由数组自己去判断 //字符是否相等,如果是同一个字符就自动++ for (int str_index=0;str_index<strlen(str);str_index++) { cout_array[str[str_index]]++; } //将含有参数输出即可 for (int count_arrry_index=0;count_arrry_index<256;count_arrry_index++) { if (cout_array[count_arrry_index]>0) { cout<<char(count_arrry_index)<<": "<<cout_array[count_arrry_index]<<endl; } } return 0; }