| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 487 人关注过本帖
标题:各位大侠,小弟请教个问题
取消只看楼主 加入收藏
niitzz
Rank: 1
等 级:新手上路
帖 子:12
专家分:3
注 册:2011-7-20
收藏
 问题点数:0 回复次数:0 
各位大侠,小弟请教个问题
下面程序不知道错在何处,请高手指教


#include "stdafx.h"
#include <iostream>
#include <cstring>

using namespace std;

class String
{
public:
    String(){p=NULL;}
    String(char *str);
    void display();
    bool operator>(String &String2);
    bool operator<(String &String2);
    bool operator==(String &String2);
    void compare(String &,String &);
private:
    char *p;
};

String::String(char *str)
{
    p=str;
}

bool String::operator>(String &String2)
{
    if(strcmp(this->p,String2.p)>0)
        return true;
    else return false;
}

bool String::operator<(String &String2)
{
    if(strcmp(this->p,String2.p)<0)
        return true;
    else return false;
}

bool String::operator==(String &string2)
{
    if(strcmp(this->p,string2.p)==0)
        return true;
    else return false;
}

void String::display()
{
    cout<<p;
}


void String::compare(String &string1,String &string2)
{
    if(operator>(string2)==1)
    {string1.display();cout<<">";string2.display();}
    else
        if(operator<(string2)==1)
        {string1.display();cout<<"<";string2.display();}
        else
            if(operator==(string2)==1)
            {string1.display();cout<<"=";string2.display();}
            cout<<endl;
}

void main()
{
    String string1("hello"),string2("book"),string3("computer"),string4("hello");
    compare(string1,string2);
    compare(string2,string3);
    compare(string3,string4);
   
}
搜索更多相关主题的帖子: private compare display include public 
2011-10-14 20:46
快速回复:各位大侠,小弟请教个问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023432 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved