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

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

企業(yè)單頁網(wǎng)站模板推廣普通話奮進(jìn)新征程

企業(yè)單頁網(wǎng)站模板,推廣普通話奮進(jìn)新征程,找什么樣的公司幫助做網(wǎng)站,簡(jiǎn)單網(wǎng)站制作實(shí)驗(yàn)報(bào)告【小夢(mè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)寫法—— 賦…

【小夢(mè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é)撒花💞

追夢(mèng)之旅,你我同行

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

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

前言🙌

? ? 哈嘍各位友友們😊,我今天又學(xué)到了很多有趣的知識(shí)現(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;}//針對(duì)const對(duì)象設(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é)撒花💞

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

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

相關(guān)文章:

  • 網(wǎng)站如何做軟文推廣湯陰縣seo快速排名有哪家好
  • 做零食的網(wǎng)站有哪些線上營(yíng)銷推廣方案
  • 織夢(mèng)企業(yè)網(wǎng)站源碼長(zhǎng)沙網(wǎng)站制作主要公司
  • 口碑好網(wǎng)站制作公司哪家好地推
  • 網(wǎng)站怎么做百度商橋百度客服電話人工服務(wù)熱線電話
  • 網(wǎng)站建設(shè)推廣方案排名優(yōu)化工具
  • 安陽市地圖蘇州seo快速優(yōu)化
  • 做代練網(wǎng)站能備案營(yíng)銷網(wǎng)絡(luò)推廣哪家好
  • wordpress 韓版 企業(yè)seo模擬點(diǎn)擊
  • 達(dá)州住房和城鄉(xiāng)建設(shè)廳網(wǎng)站中國(guó)十大熱門網(wǎng)站排名
  • 怎么在wordpress建英文網(wǎng)站杭州seo價(jià)格
  • 中山精品網(wǎng)站建設(shè)機(jī)構(gòu)外貿(mào)網(wǎng)站如何推廣優(yōu)化
  • 物流網(wǎng)站建設(shè)公司外貿(mào)谷歌推廣怎么樣
  • 網(wǎng)站程序授權(quán)碼如何聯(lián)系百度人工客服
  • 域名網(wǎng)站可以做多個(gè)品牌產(chǎn)品嗎軟文推廣策劃方案
  • 國(guó)外專門做童裝的網(wǎng)站網(wǎng)絡(luò)營(yíng)銷的概念和含義
  • 長(zhǎng)春網(wǎng)站開發(fā)公司哪家好在線推廣
  • 網(wǎng)站置頂代碼100個(gè)成功營(yíng)銷策劃案例
  • 網(wǎng)站建設(shè)銷售問答seo查詢seo
  • 如何利用網(wǎng)絡(luò)廣告提升營(yíng)銷競(jìng)爭(zhēng)力班級(jí)優(yōu)化大師客服電話
  • 高端響應(yīng)式網(wǎng)站廣告聯(lián)盟平臺(tái)自動(dòng)賺錢
  • h5網(wǎng)站開發(fā)教程企業(yè)網(wǎng)站管理系統(tǒng)怎么操作
  • 丹陽論壇營(yíng)銷網(wǎng)站seo推廣
  • 如何看還在建設(shè)的網(wǎng)站營(yíng)銷軟文
  • 網(wǎng)站建設(shè)一年多少黑科技推廣軟件
  • 網(wǎng)站關(guān)鍵詞修改廣東東莞今日最新消息
  • 網(wǎng)站建設(shè)的公司做銷售惠州百度seo
  • 做網(wǎng)店哪個(gè)網(wǎng)站好seo排名快速
  • sketch做網(wǎng)站怎么建網(wǎng)站賣東西
  • 鄒城網(wǎng)站建設(shè)哪家便宜產(chǎn)品推廣營(yíng)銷方案