实现简单的string类
Posted vlyf
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了实现简单的string类相关的知识,希望对你有一定的参考价值。
摘要
实现了一个string类,包括基本的构造、赋值、判断、大小写等。
String API
Constructors
string();
string(const char& ch);
string(const char* str);
string(const string& str);
Informational Methods
unsigned Length() const;
int Index(char c) const;
Case Methods
void UpCase(unsigned first, unsigned last);
void LowCase(unsigned first, unsigned last);
Stream Operators
friend std::ostream& operator<<(std::ostream& os, const string& str);
friend std::istream& operator>>(std::istream& is, string& str);
Accessor Operators
const char& operator[](unsigned i) const;
char& operator[](unsigned i);
Assignment Operators
String& operator= (const String&)
String& operator+= (const String&)
String Concatenation
friend string operator+(const string& lhs, const string& rhs);
friend string operator+(const string& lhs, const char* rhs);
friend string operator+(const char* lhs, const string& rhs);
Logical Operators
friend bool operator==(const string& lhs, const string& rhs);
friend bool operator!=(const string& lhs, const string& rhs);
friend bool operator<(const string& lhs, const string& rhs);
friend bool operator>(const string& lhs, const string& rhs);
#include "string.h"
using namespace vlyf;
inline
vlyf::string::string()
{
length = 0;
data = new char[0];
}
inline
string::string(const char* str)
{
if (str)
{
unsigned n = 0;
while (str[n] != '