找回密码
 注册
搜索
热搜: 回贴
  • 前程无忧官网首页 有什么好的平台可以
  • 最新的销售平台 互联网营销的平台有哪
  • 制作网页的基本流程 网页制作和网页设
  • 【帝国CMS】输出带序号的列表(数字排
  • 网站建设公司 三一,中联,极东泵车的
  • 织梦 建站 织梦网站模版后台怎么更改
  • 云服务官网 哪些网站有免费的简历模板
  • 如何建网站要什么条件 建网站要用什么
  • 吉林市移动公司电话 吉林省退休人员网
  • 设计类毕业论文 网站设计与实现毕业论
查看: 916|回复: 0

请教:编译成功但运行结果不成功呢

[复制链接]
发表于 2009-11-4 00:33:29 | 显示全部楼层 |阅读模式 IP:江苏扬州
今天按书上的写了个程序,检测所输入的一段文字当中,字母出现的次数,编译成功了,但不能正常运行,表现在输入完一段文字以后,程序在屏幕上输出一次,然后还让继续输入文字~~~死循环了好象。
我检查了半天,也没弄明白怎么回事,请高手指点,谢谢!

程序如下:
#include<iostream.h>
#include<iomanip>
#include<cassert>


class String;//定义新类
istream& operator>>(istream&,String&);
ostream& operator<<(ostream&,const String&);
//以下为具体定义
class String{
    public:
    String();
    String(const char*);
    String(const String&);
   
    ~String();
   
    String& operator=(const String&);
    String& operator=(const char*);
   
    bool operator==(const String&);
    bool operator==(const char*);
   
    char& operator[](int);
   
    int size(){return _size;}
    char* c_str(){return _string;}
   
    private:
    int _size;
    char* _string;
};
//以下为成员函数
inline String::String()
{
    _size=0;
    _string=0;
}
inline String::String(const char *str)
{
    if(!str){
        _size=0;_string=0;
    }
    else{
        _size=strlen(str);
        _string=new char[_size+1];
        strcpy(_string,str);
    }
}

inline String::String(const String &rhs)
{
    _size=rhs._size;
    if(!rhs._string)
    _string=0;
    else{
        _string=new char[_size+1];
        strcpy(_string,rhs._string);
    }
}

inline String::~String(){delete[] _string;}

inline String& String::operator=(const char *s)
{
    if(!s){
        _size=0;
        delete[] _string;
        _string=0;
    }
    else{
        _size=strlen(s);
        delete [] _string;
        _string=new char[_size+1];
        strcpy(_string,s);
    }
    return *this;
}

inline istream& operator>>(istream &io,String &s)
{
    const int limit_string_size=4096;
    char inBuf[limit_string_size];
   
    io>>setw(limit_string_size)>>inBuf;
    s=inBuf;
   
    return io;
}

inline ostream& operator<<(ostream &os,String &s)
{
    return os<<s.c_str();
}

inline bool String::operator==(const char *s)
{
    return strcmp(_string,s)?false:true;
}

inline bool String::operator==(const String &rhs)
{
    return strcmp(_string,rhs._string)?false:true;
}

inline char& String::operator[](int elem)
{
    assert(elem>=0&&elem<_size);
    return _string[elem];
}
  //以下为主程序
int main()
{
    int aCnt=0,eCnt=0,iCnt=0,oCnt=0,uCnt=0,theCnt=0,itCnt=0,wdCnt=0,notVowel=0;
    String buf,the("the"),it("it");
   
    //cin>>buf;
    while(cin>>buf)
        {
        ++wdCnt;
        cout<<buf<<' ';
        if(wdCnt%12==0)
        cout<<endl;
        if(buf==the||buf=="The")
        ++theCnt;
        else
        if(buf==it||buf=="It")
        ++itCnt;
        
        for(int ix=0;ix<buf.size();++ix)
        {
            switch(buf[ix])
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|小黑屋|最新主题|手机版|微赢网络技术论坛 ( 苏ICP备08020429号 )

GMT+8, 2024-9-30 21:31 , Processed in 0.170867 second(s), 13 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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