string類的簡單實現

2021-06-09 23:56:29 字數 813 閱讀 2966

#include class string ;

string::string(const char *ch)

else }

string ::string(const string &str)

string ::~string()

string &string::operator=(const string &str)

string &string::operator+=(const string &str)

const string string::operator+(const string &str)

int string::length()const

std::ostream& operator<<(std::ostream &out,const string &str)

bool string::operator==(const string &str)const

bool string::operator<(const string &str)const

bool string::operator<=(const string &str)const

bool string::operator>(const string &str)const

bool string::operator>=(const string &str)const

const char &string::operator(int index)const

char &string::operator (int index)

string類的簡單實現

string類是stl裡面個乙個基礎類,同時也是乙個容器。stl在string類裡面塞了很多東西,大概有106個成員函式,以及大量的typedef 巨集,晦澀難懂。本文只是簡單通過物件導向的方法簡單實現了乙個string,以後會在此基礎進行擴充和改進。ifndef mystring h define...

自己實現簡單的string類

1.前言 最近看了下 c primer 覺得受益匪淺。不過紙上得來終覺淺,覺知此事須躬行。今天看了類型別,書中簡單實現了string類,自己以前也學過c 不過說來慚愧,以前都是用c來寫程式,學的c 基本都忘記了,也說明自己以前對c 的理解不夠深入。基於這些,覺得有必要動手來寫寫c 的一些程式了,畢竟...

自己實現簡單的string類

1.前言 最近看了下 c primer 覺得受益匪淺。不過紙上得來終覺淺,覺知此事須躬行。今天看了類型別,書中簡單實現了string類,自己以前也學過c 不過說來慚愧,以前都是用c來寫程式,學的c 基本都忘記了,也說明自己以前對c 的理解不夠深入。基於這些,覺得有必要動手來寫寫c 的一些程式了,畢竟...