鱼C论坛

 找回密码
 立即注册
查看: 4052|回复: 2

请问下面的C++代码哪里出了错误???

[复制链接]
发表于 2012-11-10 10:46:10 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
#include<iostream.h>

#include<stdio.h>
#include <string.h>

class Count
{
public:
        Count(char,char);
        void  StartCount(char *str,char *p);
        void ShowCount();
        ~Count(){};

private:
        char *itsStr,*itsP;
};
void Count::StartCount(char *str,char *p)
{
itsStr=str;
itsP=p;

}

void ShowCount()
{
    int i,count=0;
    for(i=0;itsStr[i]!='\0';i++)
        {
        if(itsStr[i]==*itsP)
        {
        count++;
        }
        }

cout<<"字母a的个数: "<<count<<endl;


}






int  main()
{
//Count mycount;
char str[1024];
char *p=new char;
cout<<"请输入一串英文字符: "<<endl;

gets(str);
cout<<"请输入要统计的字母: "<<endl;

scanf("%c",p);

StartCount(str,p);
ShowCount();

delete new char;
return 0;
}
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2012-11-10 13:28:35 | 显示全部楼层
using namespace std;
class Count
{
public:
        void  StartCount(char *str,char *p);
        void ShowCount();
        ~Count(){};

private:
        char *itsStr,*itsP;
};
void Count::StartCount(char *str,char *p)
{
        itsStr=str;
        itsP=p;

}

void Count::ShowCount()
{
        int i,count=0;
        for(i=0;itsStr[i]!='\0';i++)
        {
                if(itsStr[i]==*itsP)
                {
                        count++;
                }
        }

        cout<<"字母a的个数: "<<count<<endl;


}






int  main()
{
        Count mycount;
        char str[1024];
        char *p=new char;
        cout<<"请输入一串英文字符: "<<endl;

        gets(str);
        cout<<"请输入要统计的字母: "<<endl;

        scanf("%c",p);

        mycount.StartCount(str,p);
        mycount.ShowCount();

        delete p;
        return 0;
}
小甲鱼最新课程 -> https://ilovefishc.com
 楼主| 发表于 2012-11-10 13:36:35 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-11-16 05:46

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表