qq_45735316 2020-04-17 10:59 采纳率: 94.1%
浏览 175
已采纳

string类里面不是对!=进行重载了吗?为什么调用不了?

/*C++ P249 6-21.编写一个函数,统计一句英文句子中字母的个数,在主程序中输入输出*/

#include <iostream>
#include <string>
#include <algorithm>
#include "ctype.h"//大小写转换的函数 
using namespace std; 
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int Statistic(string *str)
{
    int i=0,j=0;

    int a[26]={0};
        int *p=a;
    while(*(str+i)!='\0')
    {
        if((int)*(str+i)>=97&&(int)*(str+i)<=123)
        {
            *(str+i)=toupper(*(str+i));
        }
        i++;
    }
    i=0;
    while(*(str+i)!='\0')
    {
        if(*(str+i)!=' ')
            a[(int)(*(str+i)-'A')]++;
        i++;
    }
    return *p;
 } 
int main(int argc, char** argv) {
    string str;
    cin>>str;
    int *a;
    a=Statistic(str);
    int max=max(a);
    for(int i=0;i<26;i++)
    {
        int s+=a[i];
    }
    cout<<"字母总个数为"<<s<<endl;
    cout<<"A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"<<endl;
    cout<<"---------------------------------------------------"<<endl;
    for(int i=0;i<max;i++)
    {
        for(int j=0;j<26;j++)
        {
            if(a[j])
            {
                cout<<"*"<<" ";
                a[j]--;
            }
        }
        cout<<endl;
     } 
    return 0;
}
  • 写回答

1条回答 默认 最新

  • threenewbee 2020-04-17 11:02
    关注

    while(*(str+i)!='\0')
    ->
    while(*(str->c_str()+i)!='\0')
    别的类似

    之前的问题如果解决的话,已经有很多了,麻烦采纳下

    https://ask.csdn.net/my

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)