中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

企業(yè)單頁網(wǎng)站模板百度賬號中心官網(wǎng)

企業(yè)單頁網(wǎng)站模板,百度賬號中心官網(wǎng),網(wǎng)站建設(shè)費(fèi)用包括,深圳燃?xì)夤揪W(wǎng)上營業(yè)廳【小夢C嘎嘎——啟航篇】string常用接口的模擬實(shí)現(xiàn)😎 前言🙌string 模擬實(shí)現(xiàn)1、iterator 迭代器相關(guān)使用函數(shù)實(shí)現(xiàn)2、構(gòu)造函數(shù)接口實(shí)現(xiàn)3、 傳統(tǒng)寫法——拷貝構(gòu)造函數(shù)接口實(shí)現(xiàn)4、 現(xiàn)代寫法——拷貝構(gòu)造函數(shù)接口實(shí)現(xiàn)5、析構(gòu)函數(shù)接口實(shí)現(xiàn)6、傳統(tǒng)寫法—— 賦…

【小夢C嘎嘎——啟航篇】string常用接口的模擬實(shí)現(xiàn)😎

  • 前言🙌
  • string 模擬實(shí)現(xiàn)
    • 1、iterator 迭代器相關(guān)使用函數(shù)實(shí)現(xiàn)
    • 2、構(gòu)造函數(shù)接口實(shí)現(xiàn)
    • 3、 傳統(tǒng)寫法——拷貝構(gòu)造函數(shù)接口實(shí)現(xiàn)
    • 4、 現(xiàn)代寫法——拷貝構(gòu)造函數(shù)接口實(shí)現(xiàn)
    • 5、析構(gòu)函數(shù)接口實(shí)現(xiàn)
    • 6、傳統(tǒng)寫法—— = 賦值運(yùn)算符重載函數(shù)接口實(shí)現(xiàn)
    • 7、現(xiàn)代寫法—— = 賦值運(yùn)算符重載函數(shù)接口實(shí)現(xiàn)
    • 8 、極致現(xiàn)代寫法—— = 賦值運(yùn)算符重載函數(shù)接口實(shí)現(xiàn)
    • 9、swap函數(shù)接口實(shí)現(xiàn)
    • 10、【】下標(biāo)訪問函數(shù)接口實(shí)現(xiàn)
    • 11、容量、大小數(shù)據(jù)獲取函數(shù)接口實(shí)現(xiàn)
    • 12、C語言格式函數(shù)字符串獲取函數(shù)接口實(shí)現(xiàn)
    • 13、擴(kuò)容函數(shù)reserve實(shí)現(xiàn)接口
    • 14、resize函數(shù)(實(shí)現(xiàn)擴(kuò)容,改變size,初始化)實(shí)現(xiàn)接口
    • 15、find函數(shù)接口實(shí)現(xiàn)
    • 16、substr 取子串函數(shù)接口實(shí)現(xiàn)
    • 17、尾插函數(shù)接口實(shí)現(xiàn)
    • 18、append函數(shù)(尾插字符串)接口實(shí)現(xiàn)
    • 19、+= 運(yùn)算符重載函數(shù)實(shí)現(xiàn)
    • 20、任意位置插入字符/字符串函數(shù)接口實(shí)現(xiàn)
    • 21、任意位置刪除len個(gè)字符
    • 22、字符串大小比較運(yùn)算符重載函數(shù)實(shí)現(xiàn)
    • 23、清空函數(shù)clear函數(shù)接口實(shí)現(xiàn)
    • 24、流插入運(yùn)算符重載函數(shù)接口實(shí)現(xiàn)
    • 25、流提取運(yùn)算符重載函數(shù)接口實(shí)現(xiàn)
    • 判空函數(shù)接口實(shí)現(xiàn)
  • 總結(jié)撒花💞

追夢之旅,你我同行

? ?
😎博客昵稱:博客小夢
😊最喜歡的座右銘:全神貫注的上吧!!!
😊作者簡介:一名熱愛C/C++,算法等技術(shù)、喜愛運(yùn)動(dòng)、熱愛K歌、敢于追夢的小博主!

😘博主小留言:哈嘍!😄各位CSDN的uu們,我是你的博客好友小夢,希望我的文章可以給您帶來一定的幫助,話不多說,文章推上!歡迎大家在評論區(qū)嘮嗑指正,覺得好的話別忘了一鍵三連哦!😘
在這里插入圖片描述

前言🙌

? ? 哈嘍各位友友們😊,我今天又學(xué)到了很多有趣的知識現(xiàn)在迫不及待的想和大家分享一下!都是精華內(nèi)容,可不要錯(cuò)過喲!!!😍😍😍

string 模擬實(shí)現(xiàn)

1、iterator 迭代器相關(guān)使用函數(shù)實(shí)現(xiàn)

        iterator begin(){return _str;}terator end(){return _str + _size;}//針對const對象設(shè)計(jì)的版本const_iterator begin() const{return _str;}const_iterator end() const{return _str + _size;}

2、構(gòu)造函數(shù)接口實(shí)現(xiàn)

		tring(const char* str = ""):_size(strlen(str)), _capacity(_size){_str = new char[_capacity + 1];strcpy(_str, str);}

3、 傳統(tǒng)寫法——拷貝構(gòu)造函數(shù)接口實(shí)現(xiàn)

// 傳統(tǒng)寫法
//s2(s1)string(const string& s):_str(nullptr),_size(0),_capacity(0){_str = new char[s._capacity + 1];strcpy(_str, s._str);_capacity = s._capacity;_size = s._size;}

4、 現(xiàn)代寫法——拷貝構(gòu)造函數(shù)接口實(shí)現(xiàn)

// s2(s1)string(const string& s):_str(nullptr), _size(0), _capacity(0){string tmp(s._str);swap(tmp);}

5、析構(gòu)函數(shù)接口實(shí)現(xiàn)

		~string(){delete[] _str;_str = nullptr;_size = _capacity = 0;}

6、傳統(tǒng)寫法—— = 賦值運(yùn)算符重載函數(shù)接口實(shí)現(xiàn)

// s2 = s3string& operator=(const string& s){if (this != &s){char* tmp = new char[s._capacity + 1];strcpy(tmp, s._str);delete[] _str;_str = tmp;_size = s._size;_capacity = s._capacity;}return *this;}

7、現(xiàn)代寫法—— = 賦值運(yùn)算符重載函數(shù)接口實(shí)現(xiàn)

// s2 = s3string& operator=(const string& s){if (this != &s){string tmp(s);//this->swap(tmp);swap(tmp);}return *this;}

8 、極致現(xiàn)代寫法—— = 賦值運(yùn)算符重載函數(shù)接口實(shí)現(xiàn)

	// s2 = s3string& operator=(string tmp){swap(tmp);return *this;}

9、swap函數(shù)接口實(shí)現(xiàn)

	void swap(string& s){std::swap(_str, s._str);std::swap(_size, s._size);std::swap(_capacity, s._capacity);}

10、【】下標(biāo)訪問函數(shù)接口實(shí)現(xiàn)

		char& operator[](size_t pos){assert(pos < _size);return _str[pos];}const char& operator[](size_t pos) const{assert(pos < _size);return _str[pos];}

11、容量、大小數(shù)據(jù)獲取函數(shù)接口實(shí)現(xiàn)

		size_t capacity() const{return _capacity;}size_t size() const{return _size;}

12、C語言格式函數(shù)字符串獲取函數(shù)接口實(shí)現(xiàn)

		const char* c_str() const{return _str;}

13、擴(kuò)容函數(shù)reserve實(shí)現(xiàn)接口

	void reserve(size_t n){if (n > _capacity){char* tmp = new char[n + 1];strcpy(tmp, _str);delete[] _str;_str = tmp;_capacity = n;}}

14、resize函數(shù)(實(shí)現(xiàn)擴(kuò)容,改變size,初始化)實(shí)現(xiàn)接口

	void resize(size_t n, char ch = '\0'){if (n <= _size){_str[n] = '\0';_size = n;}else{reserve(n);while (_size < n){_str[_size] = ch;++_size;}_str[_size] = '\0';}}

15、find函數(shù)接口實(shí)現(xiàn)

		size_t find(char ch, size_t pos = 0){for (size_t i = pos; i < _size; i++){if (_str[i] == ch){return i;}}return npos;}size_t find(const char* sub, size_t pos = 0){const char* p = strstr(_str + pos, sub);if (p){return p - _str;}else{return npos;}}

16、substr 取子串函數(shù)接口實(shí)現(xiàn)

	string substr(size_t pos, size_t len = npos){string s;size_t end = pos + len;if (len == npos || pos + len >= _size) // 有多少取多少{len = _size - pos;end = _size;}s.reserve(len);for (size_t i = pos; i < end; i++){s += _str[i];}return s;}

17、尾插函數(shù)接口實(shí)現(xiàn)

	void push_back(char ch){if (_size == _capacity){reserve(_capacity == 0 ? 4 : _capacity * 2);}_str[_size] = ch;++_size;_str[_size] = '\0';}

18、append函數(shù)(尾插字符串)接口實(shí)現(xiàn)

	void append(const char* str){size_t len = strlen(str);if (_size + len > _capacity){reserve(_size + len);}strcpy(_str + _size, str);_size += len;}

19、+= 運(yùn)算符重載函數(shù)實(shí)現(xiàn)

	string& operator+=(char ch){push_back(ch);return *this;}string& operator+=(const char* str){append(str);return *this;}

20、任意位置插入字符/字符串函數(shù)接口實(shí)現(xiàn)

	// insert(0, 'x')void insert(size_t pos, char ch){assert(pos <= _size);if (_size == _capacity){reserve(_capacity == 0 ? 4 : _capacity * 2);}// 17:17size_t end = _size + 1;while (end > pos){_str[end] = _str[end - 1];--end;}_str[pos] = ch;_size++;}//任意位置插入一個(gè)字符串void insert(size_t pos, const char* str){assert(pos <= _size);size_t len = strlen(str);if (_size + len > _capacity){reserve(_size + len);}// 挪動(dòng)數(shù)據(jù)int end = _size;while (end >= (int)pos){_str[end + len] = _str[end];--end;}strncpy(_str + pos, str, len);_size += len;}

21、任意位置刪除len個(gè)字符

	void erase(size_t pos, size_t len = npos){assert(pos < _size);if (len == npos || pos + len >= _size){_str[pos] = '\0';_size = pos;}else{size_t begin = pos + len;while (begin <= _size){_str[begin - len] = _str[begin];++begin;}_size -= len;}}

22、字符串大小比較運(yùn)算符重載函數(shù)實(shí)現(xiàn)

		bool operator<(const string& s) const{return strcmp(_str, s._str) < 0;}bool operator==(const string& s) const{return strcmp(_str, s._str) == 0;}bool operator<=(const string& s) const{return *this < s || *this == s;}bool operator>(const string& s) const{return !(*this <= s);}bool operator>=(const string& s) const{return !(*this < s);}bool operator!=(const string& s) const{return !(*this == s);}

23、清空函數(shù)clear函數(shù)接口實(shí)現(xiàn)

	void clear(){_str[0] = '\0';_size = 0;}

24、流插入運(yùn)算符重載函數(shù)接口實(shí)現(xiàn)

ostream& operator<<(ostream& out, const string& s){/*for (size_t i = 0; i < s.size(); i++){out << s[i];}*/for (auto ch : s)out << ch;return out;}

25、流提取運(yùn)算符重載函數(shù)接口實(shí)現(xiàn)

	istream& operator>>(istream& in, string& s){// 17:15繼續(xù)s.clear();//s.reserve(128);char buff[129];size_t i = 0;char ch;ch = in.get();while (ch != ' ' && ch != '\n'){buff[i++] = ch;if (i == 128){buff[i] = '\0';s += buff;i = 0;}//s += ch;ch = in.get();}if (i != 0){buff[i] = '\0';s += buff;}return in;}

判空函數(shù)接口實(shí)現(xiàn)

		bool empty()const{return _size == 0;}

總結(jié)撒花💞

? ?希望大家通過閱讀此文有所收獲
? ?😘如果我寫的有什么不好之處,請?jiān)谖恼孪路浇o出你寶貴的意見😊。如果覺得我寫的好的話請點(diǎn)個(gè)贊贊和關(guān)注哦~😘😘😘

http://www.risenshineclean.com/news/48638.html

相關(guān)文章:

  • 幫境外賭場做網(wǎng)站是否有風(fēng)險(xiǎn)交換友情鏈接的網(wǎng)站標(biāo)準(zhǔn)是什么
  • 網(wǎng)站建設(shè)哪家好中國新聞
  • 谷歌優(yōu)化 網(wǎng)站建設(shè)百度推廣怎么看關(guān)鍵詞排名
  • 貴州遵義疫情最新消息合肥網(wǎng)站優(yōu)化方案
  • 效果圖制作網(wǎng)站20個(gè)排版漂亮的網(wǎng)頁設(shè)計(jì)
  • python網(wǎng)頁制作實(shí)例指定關(guān)鍵詞seo報(bào)價(jià)
  • 做軟裝什么網(wǎng)站可以嗎建什么網(wǎng)站可以長期盈利
  • 自己做的電影網(wǎng)站犯法嗎簡述網(wǎng)絡(luò)營銷的特點(diǎn)及功能
  • 網(wǎng)站設(shè)計(jì)流程長沙互聯(lián)網(wǎng)推廣公司
  • 社交網(wǎng)站推廣怎么做做一個(gè)網(wǎng)站
  • 成都誰做捕魚網(wǎng)站英文外鏈代發(fā)
  • 網(wǎng)絡(luò)營銷的目的seo專業(yè)培訓(xùn)學(xué)費(fèi)多少錢
  • 張家港做網(wǎng)站多少錢條友網(wǎng)
  • 忠縣網(wǎng)站建設(shè)深圳網(wǎng)站建設(shè)優(yōu)化
  • 秦皇島平臺公司seo外鏈發(fā)布技巧
  • 網(wǎng)站手機(jī)端打不開產(chǎn)品銷售方案與營銷策略
  • 帶有響應(yīng)式的網(wǎng)站天津seo優(yōu)化排名
  • 現(xiàn)貨黃金什么網(wǎng)站可以做直播成都sem優(yōu)化
  • dw做網(wǎng)站常用標(biāo)簽傳智播客培訓(xùn)機(jī)構(gòu)官網(wǎng)
  • flash 網(wǎng)站制作青島網(wǎng)站建設(shè)方案優(yōu)化
  • wap網(wǎng)站定位鎮(zhèn)江百度關(guān)鍵詞優(yōu)化
  • 網(wǎng)站建設(shè)聯(lián)系方式做網(wǎng)絡(luò)優(yōu)化哪家公司比較好
  • delphi做網(wǎng)站開發(fā)企業(yè)網(wǎng)站制作步驟
  • 仿糗事百科wordpress搜索引擎優(yōu)化面對哪些困境
  • 大連做網(wǎng)站哪家服務(wù)好磁力鏈最好用的搜索引擎
  • 數(shù)碼網(wǎng)站建設(shè)總體目標(biāo)軟文世界官網(wǎng)
  • 深圳網(wǎng)站建設(shè)黃浦網(wǎng)絡(luò)友情鏈接是免費(fèi)的嗎
  • 一級a做愛av網(wǎng)站百度新聞官網(wǎng)
  • 網(wǎng)站受眾群體設(shè)計(jì)網(wǎng)站的軟件
  • 專門做頭像的網(wǎng)站一個(gè)產(chǎn)品的市場營銷策劃方案