定义string 类 重载运算符

来源:百度知道 编辑:UC知道 时间:2024/06/07 15:16:50
具体问题:
定义一个字符串String类,并定义下列重载运算符
1)赋值运算符:=
2)串连接运算符:+=
3)关系运算符:>、<、==

100分的悬赏并不是要你的思路,而是要具体的函数,包括验证是否正确的main()函数。
你不在乎,可是我在乎,哪来的**,别在这里放臭*!!!

对不起,忘了说了,这是c++的练习题。

这是我早期学习的代码,它是一个头文件。将所有的函数都包括在其中。

//these codes is a class that deals with the operation of string
//its function is like as this language such as BASIC, PASCAL etc.
//it should be included these programs that deal with many strings.
#include <iostream.h>
#include <string.h>
#ifndef String_HPP
#define String_HPP

class String{
private:
char *pDate;
int nLength;
public:
String();
String(char *s);
String(String &str);
~String();

void copy(char *s);
void cat(char *s);

char *string(void) const{return pDate;}
int len(void) const{return nLength;}

String& operator=(const String &s)
{copy(s.string());return *this;}
operator const char*()
{return string();}

friend String operator+(String str1,String str2);
friend String operator+(String str,char *s);
// frined String operator+(char *s,String str)