当前位置: 首页 > news >正文

跨境电商网站平台东莞软件开发培训

跨境电商网站平台,东莞软件开发培训,取名算命网站的源代码asp+access,wordpress素才上回我们完成了string类的模拟实现#xff0c;不过之前写的传统写法本篇#xff0c;我们将要对其进行一些改进#xff0c;写成参考的是现代写法#xff0c;这样写可以提高可读性。 上回我们写好的string类 //string.h #pragma once#define _CRT_SECURE_NO_WARNINGS 1 #p…上回我们完成了string类的模拟实现不过之前写的传统写法本篇我们将要对其进行一些改进写成参考的是现代写法这样写可以提高可读性。 上回我们写好的string类 //string.h #pragma once#define _CRT_SECURE_NO_WARNINGS 1 #pragma once #includeiostream #includeassert.h using namespace std;namespace STring {class string{public:typedef char* iterator;typedef const char* const_iterator;iterator begin();iterator end();const_iterator begin() const;const_iterator end() const;//string();string(const char* str );string(const string s);string operator(const string s);~string();const char* c_str() const;size_t size() const;char operator[](size_t pos);const char operator[](size_t pos) const;void reserve(size_t n);void push_back(char ch);void append(const char* str);string operator(char ch);string operator(const char *str);void insert(size_t pos, char ch);void insert(size_t pos, const char* str);void erase(size_t pos 0, size_t len npos);size_t find(char ch, size_t pos 0);size_t find(const char* str, size_t pos 0);void swap(string s);string substr(size_t pos 0, size_t len npos);bool operator(const string s) const;bool operator(const string s) const;bool operator(const string s) const;bool operator(const string s) const;bool operator(const string s) const;bool operator!(const string s) const;void clear();private:// char _buff[16];char* _str;size_t _size;size_t _capacity;// //const static size_t npos -1;// ֧//const static double N 2.2;const static size_t npos;};istream operator (istream is, string str);ostream operator (ostream os, const string str); } //string.cpp #includestring.h namespace STring {const size_t string::npos -1;string::iterator string::begin(){return _str;}string::const_iterator string::begin() const{return _str;}string::iterator string::end(){return _str _size;}string::const_iterator string::end() const{return _str_size;}string:: string(const char* str):_size(strlen(str)){_str new char[_size1];_capacity _size1;strcpy(_str, str);}string::string(const string s){_str new char[s._capacity];strcpy(_str, s._str);_size s._size;_capacity s._capacity;}string::~string(){delete[] _str;_str nullptr;_size _capacity 0;}const char* string::c_str() const{return _str;}size_t string :: size() const{return _size;}void string::reserve(size_t n){if (n _capacity){char* tmp new char[n 1];strcpy(tmp, _str);delete[] _str;_str tmp;_capacity n;}}void string::push_back(char ch){if (_size _capacity){size_t newcapacity _capacity 0 ? 4 : _capacity * 2;reserve(newcapacity);}_str[_size] ch;_str[_size 1] \0;_size;}void string::append(const char* str){size_t len strlen(str);if (_size len _capacity){reserve(_size len);}strcpy(_str _size, _str);_size len;insert(_size, _str);}void string::insert(size_t pos, char ch){assert(pos _size);if (_size _capacity){size_t newcapacity _capacity 0 ? 4 : _capacity * 2;reserve(newcapacity);}size_t end _size 1;while (end pos){_str[end] _str[end - 1] 1;--end;}_str[pos] ch;_size;}void string::insert(size_t pos, const char* str){assert(pos _size);int len strlen(str);if (_size len _capacity){reserve(_capacitylen);}size_t end _size len;while (end poslen1){_str[end] _str[end - len];--end;}memcpy(_strpos,str,len);_size len;}void string::erase(size_t pos, size_t len){assert(pos _size);if (len _size - pos){_str[pos] \0;_size len;}else{strcpy(_str pos, _str pos len);_size len;}}size_t string::find(char ch, size_t pos){for (size_t i pos; i _size; i){if (_str[i] ch){return i;}}return npos;}size_t string::find(const char* str, size_t pos){char* p strstr(_str pos, str);return p - _str;}void string::swap(string s){std::swap(_str, s._str);std::swap(_size, s._size);std::swap(_capacity, s._capacity);}string string::substr(size_t pos, size_t len){if (len _size - pos){string sub(_str pos);return sub;}else{string sub;sub.reserve(len);for (size_t i 0; i len; i){sub _str[i pos];}return sub;}}string string:: operator(const string s){if (this ! s){char* tmp new char[s._capacity];strcpy(tmp, s._str);delete[] _str;_str tmp;_size s._size;_capacity s._capacity;}return *this;}char string::operator[](size_t pos){if (pos _size)return _str[pos];}const char string::operator[](size_t pos) const{if (pos _size)return _str[pos];}string string::operator(char ch){push_back(ch);return *this;}string string::operator(const char* str){append(str);return *this;}bool string::operator(const string s) const{return strcmp(_str, s._str) 0;}bool string::operator(const string s) const{return !(*this s);}bool string::operator(const string s) const{return *this s || *this s;}bool string::operator(const string s) const{return !(*this s);}bool string::operator(const string s) const{return strcmp(_str, s._str) 0;}bool string::operator!(const string s) const{return !(*this s);}void string::clear(){_str[0] \0;_size 0;}istream operator (istream is, string str){str.clear();char ch is.get();while (ch ! ch ! \n){str ch;ch is.get();}return is;}ostream operator (ostream os, const string str){for (size_t i 0; i str.size(); i){os str[i];}return os;} } 以下是现代写法对于 传统写法的改进 一、push_back 传统写法 void string::push_back(char ch) {if (_size _capacity){size_t newcapacity _capacity 0 ? 4 : _capacity * 2;reserve(newcapacity);}_str[_size] ch;_str[_size 1] \0;_size; } 现代写法 void string::push_back(char ch){insert(_size, ch);} 二、append 传统写法 void string::append(const char* str){size_t len strlen(str);if (_size len _capacity){reserve(_size len);}strcpy(_str _size, _str);_size len;insert(_size, _str);} 现代写法 void string::append(const char* str){insert(_size, str);}
http://www.zqtcl.cn/news/761867/

相关文章:

  • 怎样做网站表白墙东莞商城网站推广建设
  • 郑州郑州网站建设河南做网站公司哪家好爱站长尾词挖掘工具
  • dede网站地图文章变量网站qq 微信分享怎么做
  • 越南做网站网站建设以及运营方面
  • 广西建网站哪家好网站关闭与域名备案
  • 网站开发版本号婚庆网站建设策划案费用预算
  • 厦门建设网站制作中山市哪家公司做网站
  • 网站路径wordpress制作电商网站
  • 江西网站开发哪家专业装饰设计公司网站
  • 企业网站策划实训Wordpress 主题简化
  • 做网站点击挣钱不兰州工程建设信息网站
  • 网站说服力 营销...免费看片网站
  • 深圳招聘网站大全制作网站软件下载
  • 网站建设说明哈尔滨网站建设渠道
  • 一 网站建设管理基本情况设计类的网站
  • wordpress产品编辑如何优化wordpress
  • 网站后台更新缓存失败网站平台规划方案
  • 网站开发需求分析主要内容saas建站系统是怎么实现的
  • 做qq头像的网站有哪些wordpress怎么部署到虚拟linux服务器
  • 征求网站建设企业网站建设word
  • 市民服务中心网站建设小型公众号开发
  • 服装网站建设策划书论文基层建设刊物网站
  • 网站建设合同技术开发合同范本wordpress备份和还原
  • 物流信息平台网站建设一流本科专业建设点网站
  • 天猫网站建设的目标是什么装潢设计软件
  • 电商网站首页图片网站功能模块建设
  • 邮件服务器是不是网站服务器黄江网站建设公司
  • 科技部网站方案网页设计网站设计欣赏
  • 自贡建设机械网站网站策划与运营课程认知
  • 公司做网站该注意哪些廊坊seo