C++ String类的实现
来源:互联网 发布:淘宝修改发货地 编辑:程序博客网 时间:2024/05/16 18:21
#include<iostream>
using namespace std;
class String{
friend ostream& operator<< (ostream&,String&);
public:
String(const char* str=NULL); //赋值构造兼默认构造函数(char)
String(const String &other); //赋值构造函数(String)
String& operator=(const String&other); //operator=
String operator+(const String &other)const; //operator+
bool operator==(const String&); //operator==
char& operator[](unsigned int); //operator[]
size_t size(){return strlen(m_da
~String(void) {delete[] m_da
private:
char *m_da
};
inline String::String(const char* str)
{
if (!str) m_da
else
{
m_da
strcpy(m_da
}
}
inline String::String(const String& other)
{
if(!other.m_da
else
{
m_da
strcpy(m_da
}
}
inline String& String::operator=(const String& other)
{
if (this!=&other)
{
delete[] m_da
if(!other.m_da
else
{
m_da
strcpy(m_da
}
}
return *this;
}
inline String String::operator+(const String &other)const
{
String newString;
if(!other.m_da
newString = *this;
else if(!m_da
newString = other;
else
{
newString.m_da
strcpy(newString.m_da
strcat(newString.m_da
}
return newString;
}
inline bool String::operator==(const String &s)
{
if ( strlen(s.m_da
return false;
return strcmp(m_da
}
inline char& String::operator[](unsigned int e)
{
if (e>=0&&e<=strlen(m_da
return m_da
}
ostream& operator<<(ostream& os,String& str)
{
os << str.m_da
return os;
}
- [C++]String类的实现
- [C++]String类的实现
- [C++]String类的实现
- C++String类的实现
- 【c++】string类的实现
- C++string类的实现
- C++string类的实现
- C++String类的实现
- C++string类的实现
- C/C++string类的实现
- C++string类的一个实现
- C++string类的简单实现
- c++string类的简单实现
- C++—String类接口的实现
- 【C/C++】String类实现
- C string buffer的实现
- C++:模拟实现string类
- 模拟实现string类(c++)
- Android中再按一次退出和完美退出整个应用程序
- 使用 CAS 在 Tomcat 中实现单点登录
- 如何打包Python脚本使用的Python库[C++嵌入Python]
- Linux子系统系列-SPI
- 什么情况下,VC的DLL工程只生成DLL,不生成LIB文件
- C++ String类的实现
- 隐藏NGINX banner 和版本号
- EAGLE 输出gerber
- myeclipse复制粘贴快捷键不可用的解决办法
- webveiw加载html
- 10gRAC在安装了DB的情况下重建CRS
- android中如何更新adt
- 【Objective-C】06-点语法
- C++ 异常 与 ”为什么析构函数不能抛出异常“ 问题