求助数据结构中自定义String类,要C++描述的

来源:百度知道 编辑:UC知道 时间:2024/07/04 11:16:50
我要详细的代码,之前在网上也没有找到,希望哪位能够在回答的时候把代码都发过来,我要String类的定义还有各个成员函数具体的代码
class String
{
public:
String();
String(const char *p);
~String(){delete []str;}
int Length(){return n;} //返回当前串对象的长度
void Clear(){n=0;} //置为空串
void Assign(String &S); //串S的值赋给当前对象
void Concat(String &b); //将串b连接在当前串对象之后
void Insert(String &P,int i); //将串P插在当前串对象的位置i处
void Delete(int i ,int len); //从当前串对象的位置i起删除len个字符
String Substr(int i,int len); //返回当前串对象中,从位置i开始的len个字符组成的字串
int Find(int i,String P); //返回字串P在当前串对象中的位置。若当前串对象不包含串P,则返回-1
private:
int n;
char *str;
}

之前由于没有说清楚,我要的是自己定义的string类,希望哪位强人能够自己写一段代码,定义已经补充了,函数的参数,返回值类型什么的都可以改,但是功能一定要达到

STL中已经包含源代码。
可以看看你的VC安装目录下,include文件夹下的"STRING"文件。
你找不到,我帮你贴在下面:

// string standard header

#if _MSC_VER > 1000
#pragma once
#endif

#ifndef _STRING_
#define _STRING_
#include <istream>

#ifdef _MSC_VER
#pragma pack(push,8)
#endif /* _MSC_VER */
_STD_BEGIN
// basic_string TEMPLATE OPERATORS
template<class _E, class _Tr, class _A> inline
basic_string<_E, _Tr, _A> __cdecl operator+(
const basic_string<_E, _Tr, _A>& _L,
const basic_string<_E, _Tr, _A>& _R)
{return (basic_string<_E, _Tr, _A>(_L) += _R); }
template<class _E, class _Tr, class _A> inline
basic_string<_E, _Tr, _A> __cdecl operator+(const _E *_L,
const basic_string<_E, _Tr, _A>& _R)
{return (basic_string<_E, _Tr, _A>(_L) += _R); }
template<class _E, class _Tr