C++编写一字符串类的实现程序!

来源:百度知道 编辑:UC知道 时间:2024/05/17 07:51:48
要求:
(1)建立字符串类
(2)利用运算符重载的概念实现两个字符串的等于、小于和大于的比较运算;
(3)实现字符串的常用操作:串赋值、串插入、串删除、串连接与求子串。

#include "iostream.h"

////////////////////////////////////////////////////////////
// string类声明部分
//
//
////////////////////////////////////////////////////////////
#include "string.h"
#define TRIM_LEFT 1
#define TRIM_RIGHT 2
#define TRIM_BOTH 0

class string
{
public:
string();
string( const char *src );
string( string &src );
~string();
//操作符重载
void operator = ( const char *src );
//char * operator + ( string &add2 );
string operator + ( string &add2 );
operator char *();
//成员函数
const char *ToString();
char GetAt( int index );
int Len();
int FindFirstSub( string substr , int start );
bool InStr( string substr );
string Trim( int part );
string Left( int sublen );
string Right( int sublen );
string Mid( int start , int sublen );
void Replace( string strNeedReplaced , string strReplace );