C++爱好者 - 网友留言

1118阅读 0评论2008-12-17 3JTwF2T
分类:

实现一个字符串类String,可以使用c语言字符串库.
class Sting
{
pulic:
     String(const char* str=null);
     String(const String& str);
     ~String();
     //字符串长度
     int Length();
     //赋值
     Sting& operator=(const Sting& rhs);
     Sting& operator=(const char* rhs);
     //字符串比较
     bool operator<(const Sting& str);
     bool operator>(const Sting& str);
     bool operator<=(const Sting& str);
     bool operator>=(const Sting& str);
     bool operator==(const Sting& str);
     bool operator!(const Sting& str);
     //字符串连接
     friend const String operator+(const String& s1,const String& s2);
     //读写字符串
     friend istream& operator>>(istream& in,String& str);
     friend ostream& operator<<(istream& out,const String& str);
     //查找
     int find(const String& str);
     int find(const char* str);
     //求子串
     String substr(int start,int length);
     //插入子串
     String& insert(int start,const String& str);
     String& insert(int start,const char* str);
private:
     char* data;
     int size;
};
     
     




--------------------next---------------------

上一篇:C++爱好者 - 网友留言
下一篇:C++爱好者 - 网友留言