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

网站被恶意解析东台网站建设公司

网站被恶意解析,东台网站建设公司,网站如何添加统计代码,国内代理个人主页#xff1a;仍有未知等待探索-CSDN博客 专题分栏#xff1a;C 请多多指教#xff01; 目录 一、标准库中的string 1、了解 2、string类常用接口说明 1、常见的构造函数 2、容量操作 ​编辑 3、访问及遍历操作 4、修改操作 5、非成员函数 二、string类实现 … 个人主页仍有未知等待探索-CSDN博客 专题分栏C                                                         请多多指教 目录 一、标准库中的string 1、了解 2、string类常用接口说明 1、常见的构造函数 2、容量操作 ​编辑 3、访问及遍历操作 4、修改操作 5、非成员函数 二、string类实现 1、string类的大体框架 2、构造和析构函数  3、迭代器  4、成员函数  5、非成员函数 三、问题 1、深拷贝和浅拷贝问题 2、strcpymemcpy 四、总代码 一、标准库中的string 1、了解 1、string是表示字符串的字符串类 2、该类的接口与常规容器的接口基本相同再添加了一些专门用来操作string的常规操作。 2、string类常用接口说明 下面的函数都可以去下面的网址进行查文档来看函数的功能。接下来我会实现这个string类 string - C Reference 1、常见的构造函数 string类对象的常见构造 函数名称功能说明string()        构造空的string类即空字符串string(const char*s) 用c_str()来构造string类对象 string(size_t n, char c)string类对象中包含n个字符cstring(const string s)拷贝构造函数 2、容量操作   3、访问及遍历操作 4、修改操作 5、非成员函数 二、string类实现 实现string类能让我们更好的明白模板的使用函数重载等等。 1、string类的大体框架 #include iostream #include cstring #include assert.h using namespace std;class string { public:private:char* _str; // string存的字符串size_t _size; // string中字符串的长度 size_t _capacity; // string的容量 }; 2、构造和析构函数  string():_str(nullptr),_size(0),_capacity(0) {} string(const char* str):_size(strlen(str)),_capacity(_size) {_str new char[_capacity 1];strcpy(_str, str); } string(const string str):_str(new char[str._capacity 1]),_size(str._size),_capacity(str._capacity) {strcpy(_str, str._str); } ~string() {delete[] _str;_str nullptr;_size 0;_capacity 0; } 3、迭代器  typedef char* iterator; iterator begin() {return _str; } iterator end() {return _str _size; }4、成员函数  string operator(const string str) {char* tmp new char[str._capacity 1];strcpy(tmp, str._str);delete[] _str;_str tmp;_size str._size;_capacity str._capacity;return *this; } void reserve(int x) {if (_capacity x){char* tmp new char[x 1];strcpy(tmp, _str);delete[] _str;_str tmp;_capacity x;} } void swap(string str) {std::swap(_str, str._str);std::swap(_size, str._size);std::swap(_capacity, str._capacity); } const char* c_str() const {return _str; } void clear() {_str[0] \0;_size 0; } void insert(int index, const string str) {int len str._size;assert(index 0 index _size);if (_size len _capacity){reserve(_capacity len);}for (int i _size - 1; i index; i -- ){_str[i len] _str[i];}for (int j 0, i index; j str._size; j ,i ){_str[i] str._str[j];}_size len; } void insert(int index, char ch) {assert(index 0 index _size);if (_size 1 _capacity){reserve(2 * _capacity);_capacity * 2;}for (int i _size - 1; i index; i -- ){_str[i 1] _str[i];}_str[index] ch;_size ;} void append(const string str) {int len str._size;if (len _size _capacity){reserve(len _size);_capacity len * _size;}int end _size;for (int i 0; i str._size; i ,end ){_str[end] str._str[i];}_size len; } string operator(const string str) {append(str);return *this; } void push_back(const char ch) {if (_size 1 _capacity){reserve(2 * _capacity);}_capacity * 2;_str[_size] ch;_size ; } int size() const {return _size; } int capacity() const {return _capacity; } bool empty() const {return _size 0; } void resize(int n, char ch \0) {if (n _size){for (int i n; i _size; i ){_str[i] \0;}}else if (n 1 _capacity){for (int i _size; i n; i ){_str[i] ch;}}else{reserve(n);} } char operator[](size_t index) {assert(index _size);return _str[index]; } const char operator[](size_t index)const {assert(index _size);return _str[index]; } bool operator(const string str) {int ret strcmp(_str, str.c_str());return ret 0; } bool operator!(const string str) {return !(*this str); } bool operator(const string str) {int ret strcmp(_str, str.c_str());return ret 0; } bool operator(const string str) {int ret strcmp(_str, str.c_str());return ret 0; } bool operator(const string str) {return *this str || *this str; } bool operator(const string str) {return *this str || *this str; } int find (char c, size_t pos 0) const {assert(pos _size);for (int i pos; i _size; i ){if (_str[i] c) return i;}return npos; } int find (const char* s, size_t pos 0) const {char* p strstr(_str pos, s);if (p ! nullptr){return p - _str;}return npos; } string erase (size_t pos 0, size_t len npos) {assert(pos _size);if (len npos || len _size - pos){_str[pos] \0;_size pos;}else{int i 0;for (i pos len; i _size; i ){_str[i - len] _str[i];}_str[i] \0;_size - len;}return *this; } 5、非成员函数 ostream operator(ostream out, const string str){int len str._size;for (int i 0; i len; i ){out str._str[i];}return out;}istream operator(istream in, string str){str.clear();char ch in.get();char buff[128];int i 0;while (ch ! ch ! \n){buff[i ] ch;if (i 127){buff[i] \0;str buff;i 0;}ch in.get();}if (i ! 0){buff[i] \0;str buff;}return in;} } 三、问题 1、深拷贝和浅拷贝问题 浅拷贝也称位拷贝编译器只是将对象中的值拷贝过来。如果对象中管理资源最后就会导致多个对象共享同一份资源当一个对象销毁时就会将该资源释放掉而此时另一些对象不知道该资源已经被释放以为还有效所以当继续对资源进项操作时就会发生发生了访问违规。 深拷贝每个对象都有一份独立的资源不要和其他对象共享。如果一个类中涉及到资源的管理其拷贝构造函数、赋值运算符重载以及析构函数必须要显式给出。一般情况都是按照深拷贝方式提供。 2、strcpymemcpy 通过下面的例子也能清晰的看出来这两个拷贝函数都是浅拷贝。所以在用的时候需要小心谨慎。 四、总代码 #include iostream #include cstring #include assert.h using namespace std;namespace my {class string{public:string():_str(nullptr),_size(0),_capacity(0){}string(const char* str):_size(strlen(str)),_capacity(_size){_str new char[_capacity 1];strcpy(_str, str);}string(const string str):_str(new char[str._capacity 1]),_size(str._size),_capacity(str._capacity){strcpy(_str, str._str);}~string(){delete[] _str;_str nullptr;_size 0;_capacity 0;}typedef char* iterator;iterator begin(){return _str;}iterator end(){return _str _size;}string operator(const string str){char* tmp new char[str._capacity 1];strcpy(tmp, str._str);delete[] _str;_str tmp;_size str._size;_capacity str._capacity;return *this;}void reserve(int x){if (_capacity x){char* tmp new char[x 1];strcpy(tmp, _str);delete[] _str;_str tmp;_capacity x;}}void swap(string str){std::swap(_str, str._str);std::swap(_size, str._size);std::swap(_capacity, str._capacity);}const char* c_str() const{return _str;}void clear(){_str[0] \0;_size 0;_capacity 0;}void insert(int index, const string str){int len str._size;assert(index 0 index _size);if (_size len _capacity){reserve(_capacity len);}for (int i _size - 1; i index; i -- ){_str[i len] _str[i];}for (int j 0, i index; j str._size; j ,i ){_str[i] str._str[j];}_size len;}void insert(int index, char ch){assert(index 0 index _size);if (_size 1 _capacity){reserve(2 * _capacity);_capacity * 2;}for (int i _size - 1; i index; i -- ){_str[i 1] _str[i];}_str[index] ch;_size ;}void append(const string str){int len str._size;if (len _size _capacity){reserve(len _size);_capacity len * _size;}int end _size;for (int i 0; i str._size; i ,end ){_str[end] str._str[i];}_size len;}string operator(const string str){append(str);return *this;}void push_back(const char ch){if (_size 1 _capacity){reserve(2 * _capacity);}_capacity * 2;_str[_size] ch;_size ;}int size() const{return _size;}int capacity() const{return _capacity;}bool empty() const{return _size 0;}void resize(int n, char ch \0){if (n _size){for (int i n; i _size; i ){_str[i] \0;}}else if (n 1 _capacity){for (int i _size; i n; i ){_str[i] ch;}}else{reserve(n);}}char operator[](size_t index){assert(index _size);return _str[index];}const char operator[](size_t index)const{assert(index _size);return _str[index];}bool operator(const string str){int ret strcmp(_str, str.c_str());return ret 0;}bool operator!(const string str){return !(*this str);}bool operator(const string str){int ret strcmp(_str, str.c_str());return ret 0;}bool operator(const string str){int ret strcmp(_str, str.c_str());return ret 0;}bool operator(const string str){return *this str || *this str;}bool operator(const string str){return *this str || *this str;}int find (char c, size_t pos 0) const{assert(pos _size);for (int i pos; i _size; i ){if (_str[i] c) return i;}return npos;}int find (const char* s, size_t pos 0) const{char* p strstr(_str pos, s);if (p ! nullptr){return p - _str;}return npos;}string erase (size_t pos 0, size_t len npos){assert(pos _size);if (len npos || len _size - pos){_str[pos] \0;_size pos;}else{int i 0;for (i pos len; i _size; i ){_str[i - len] _str[i];}_str[i] \0;_size - len;}return *this;}friend ostream operator(ostream out, const string str);friend istream operator(istream in, string str);private:char* _str; // string存的字符串size_t _size; // string中字符串的长度 size_t _capacity; // string的容量static const size_t npos -1;};inline ostream operator(ostream out, const string str){int len str._size;for (int i 0; i len; i ){out str._str[i];}return out;}inline istream operator(istream in, string str){str.clear();char ch in.get();char buff[128];int i 0;while (ch ! ch ! \n){buff[i ] ch;if (i 127){buff[i] \0;str buff;i 0;}ch in.get();}if (i ! 0){buff[i] \0;str buff;}return in;} } 谢谢大家
http://www.zqtcl.cn/news/21645/

相关文章:

  • 个人求职网站如何做深圳光明建设局官方网站
  • 杭州 网站开发全国装修公司大概多少家
  • 无锡网站营销公司湛江有帮公司做网站
  • 网站单页制作教程网站空间代理
  • 河间网站网站建设网站定制开发前期要有一定的规划
  • 新手学网站建设视频教程共30课高清版wordpress响应式图片主题
  • 免费简历模板的网站域名先解析后做网站
  • 男人需要网站响应式网站怎样做
  • 整站优化seo个人网站做交易类的赚钱吗
  • 自己的电脑做服务器建立网站的方法商城类的网站一般怎么做
  • 用个人电脑做服务器建网站台州电子商务网站建设
  • 网站建设文化信息设计行业网站建设
  • 做任务换流量的网站专业做设计的网站
  • 网站设计与平面设计区别wordpress导航添加图片
  • phpcms做网站好吗湖南人文科技学院王牌专业
  • 如何搜索易思cms做的网站关键词点击价格查询
  • 如何搜索asp网站wordpress订单管理系统
  • 修改网站模板科技馆网站建设背景
  • 服务器做php网站区块链外包开发
  • 用猴子做标志起网站名叫什么好怎么做能够让网站流量大
  • 网站建设模板素材wordpress 来必力
  • 北京网站建设公司价格苏州工业园区公积金
  • 南京做企业号微网站营销中国建设公司排名
  • 写文章的网站东莞网站建设价格
  • 网站301和302手赚网 wordpress
  • 北京网站建设公司朝阳广东城乡建设厅网站
  • 汇算清缴在哪个网站做网站制作 北京
  • 免费推广网站在线用代码做网站
  • 赣州市建设局建管科网站c2c模式流程图
  • 网站建设以哪种销售方式好做a免费网站