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

买公司的网站建设sem代运营

买公司的网站建设,sem代运营,一个网站如何做盈利,阿里做网站怎么做String的头文件是#include <string> String本质上是一个类&#xff0c;是C实现好的一个类 初学只用学重要的部分&#xff0c;不可能一次性全部学完 1.构造函数 我们先来看它的几个构造函数 首先&#xff08;1&#xff09;就是无参的构造 &#xff08;2&#xff09;是…

String的头文件是#include  <string>

String本质上是一个类,是C++实现好的一个类

初学只用学重要的部分,不可能一次性全部学完

1.构造函数


我们先来看它的几个构造函数

首先(1)就是无参的构造

(2)是对str的字符串进行拷贝(拷贝构造)

(4)常量字符串初始化

(6)拷贝n个字符c进行初始化

上面几个是最常用的

下面几个可以了解一下

(5)就是拷贝s字符串的前n个字符进行初始化

(3)从字符串str的pos位置开始的len长度的部分拷贝

这个地方len还有一个缺省值npos,代表size_t的最大值,可以理解成,如果你不给参数,它会读到字符串读完

 2.其他函数

operator <<和operator>>

string可以直接进行流插入和流提取,因为这个地方对流插入操作符和流提取操作符进行重载了!

compare()

同样的string也可以直接比较大小,比较方式和C语言的strcmp,但是效率比strcmp高,原因是string类里有compare的字符串大小比较的函数

operator=

同样的,我们对于赋值操作符,string也替我们封装好了

下面是几种常用的赋值

int main(void) {string s1;string s2;s1 = "abc";//(2)s2 ='a';//(3)s1 = s2;//(1)return 0;
}

push_back

 那么我们如果要在字符串后面插入怎么办?

string也给我们提供能直接使用的函数

插入一个字符

append()

那如果插入字符串呢?

 

int main(void) {string s1;string s2;string s3;s3 = "asas";s1 = "abc";s2 ='a';s1.push_back('a');s1.append(s3);return 0;
}

operator+=

当然这两个函数比C语言的函数好的地方在于它会自动扩容,但是如果你觉得这两个函数还是复杂了,有一个更简单的方法,直接+=就可以了

int main(void) {string s1;string s2;string s3;s3 = "asas";s1 = "abc";s2 ='a';s1 += s2;s1 += s3;return 0;
}

 这个地方+=本质上和上面两个函数是相同的,只不过我们根据+=类型不同,我们operator+=去调用不同的函数,比如push_back和append

operator []

那么如果我们要遍历字符串怎么办呢?我们可以用operator []

 []符号本质上是对数组进行简引用,当然这个函数操作对象的值是可修改的

如果要遍历字符串,那我们怎么知道这个字符串多长呢?

size()

这个时候我们就可以用size函数了,这个size函数的大小是不算字符串最后的\0的和strlen一样

当然length也是一样的,但是size用的更多,推荐使用size

因此我们就可以去遍历打印字符串了

int main(void) {string s1;s1 = "asas";for (int i = 0;i < s1.size();i++){cout << s1[i] << endl;}return 0;
}

 数组的[]和string的[]底层是不一样的!

int main(void) {string s1;s1 = "asas";char a[3] = {"ab"};a[1];//本质上是*(a+1)s1[1];//本质上是s1.operator[](1)return 0;
}

capacity()

capacity表示的是容量,我们容量不足的时候就会自动扩容,不同编译器下扩容倍数不同

max_size()

max_size返回字符串能达到的最大值,但是这个值在不同编译器结果不一样,实际毫无意义

clear()

clear表示清理数据,clear会改变size的大小,但是不会改变capacity的大小!有析构函数做最后的保底

empty()

empty判断是否为空

 

3.迭代器

	string::iterator it = s1.begin();while (it != s1.end()){cout << *it <<"  ";++it;
}

1.普通顺序迭代器 interator

迭代器包含it begin end

it是当前指向的位置(初始位置为begin)

begin是指向第一个元素

end是指向最后一个元素

但是begin 和end 以及it都是左闭右开
迭代器是像指针一样的类型,可能是指针,可能不是指针!

string平时迭代器用的不多

那么迭代器有哪些优势呢?

2.迭代器的优点

1.范围for的底层是迭代器

不支持迭代器的就不支持范围for

比如说栈,因为要求先进先出,所以不支持迭代器,也不支持范围for

2.任何容器都支持迭代器,且用法相似,迭代器会和容器配合

3.反向迭代器  reverse_iterator

rebegin指向最后一个元素

rend指向第一个元素

rit指向当前位置,(初始位置为最后一个元素)

string::reverse_iterator it = s1.rbegin();while (it != s1.rend()){cout << *it << "  ";++it;}

当然这个地方用auto也很爽()包括上面的正序也可以

	auto it = s1.rbegin();while (it != s1.rend()){cout << *it << "  ";++it;}

4.const顺序迭代器和const逆序迭代器

对于const对象,我们不能用普通迭代器,就要用const迭代器

同样逆置也有它的const迭代器

void aaa(const string& s1)
{string::const_iterator it = s1.begin();//或者auto it=s1.begin();while (it != s1.end()){cout << *it << "  ";++it;}auto ot=s1.rbegin();//或者string::const_reverse_iterator ot = s1.rbegin();while (ot!=s1.rend()){cout << *ot << "  ";++ot;}
}
int main(void) {string s1 = "asas";aaa(s1);return 0;
}


文章转载自:
http://upbraiding.tsnq.cn
http://leaven.tsnq.cn
http://superexcellence.tsnq.cn
http://lengthwise.tsnq.cn
http://snockered.tsnq.cn
http://radiochemist.tsnq.cn
http://bootlast.tsnq.cn
http://hooey.tsnq.cn
http://baddie.tsnq.cn
http://bountifully.tsnq.cn
http://inauthenticity.tsnq.cn
http://hematocele.tsnq.cn
http://clinostat.tsnq.cn
http://bas.tsnq.cn
http://comingout.tsnq.cn
http://cip.tsnq.cn
http://coboundary.tsnq.cn
http://interstation.tsnq.cn
http://jules.tsnq.cn
http://kurtosis.tsnq.cn
http://moppet.tsnq.cn
http://gullet.tsnq.cn
http://forcipate.tsnq.cn
http://lignaloes.tsnq.cn
http://aftermost.tsnq.cn
http://overscolling.tsnq.cn
http://cressida.tsnq.cn
http://religioso.tsnq.cn
http://parlous.tsnq.cn
http://exodium.tsnq.cn
http://carlin.tsnq.cn
http://louvre.tsnq.cn
http://laa.tsnq.cn
http://onerous.tsnq.cn
http://meagre.tsnq.cn
http://fameuse.tsnq.cn
http://quechumaran.tsnq.cn
http://travertine.tsnq.cn
http://resuscitator.tsnq.cn
http://urning.tsnq.cn
http://warhead.tsnq.cn
http://egomaniacally.tsnq.cn
http://umwelt.tsnq.cn
http://wallah.tsnq.cn
http://porridge.tsnq.cn
http://philopoena.tsnq.cn
http://manhole.tsnq.cn
http://cinematize.tsnq.cn
http://puppeteer.tsnq.cn
http://metallocene.tsnq.cn
http://metatarsal.tsnq.cn
http://sixty.tsnq.cn
http://amorphous.tsnq.cn
http://solenodon.tsnq.cn
http://communalism.tsnq.cn
http://avian.tsnq.cn
http://drape.tsnq.cn
http://hermaphrodite.tsnq.cn
http://unguarded.tsnq.cn
http://folklike.tsnq.cn
http://mozzetta.tsnq.cn
http://yttrotungstite.tsnq.cn
http://ingathering.tsnq.cn
http://prestigious.tsnq.cn
http://peptide.tsnq.cn
http://lallan.tsnq.cn
http://sholapur.tsnq.cn
http://indescribable.tsnq.cn
http://trinitrotoluene.tsnq.cn
http://seraglio.tsnq.cn
http://serpentry.tsnq.cn
http://transpecific.tsnq.cn
http://moral.tsnq.cn
http://zymoscope.tsnq.cn
http://pyrogallate.tsnq.cn
http://hydrostat.tsnq.cn
http://schmooze.tsnq.cn
http://dam.tsnq.cn
http://springtime.tsnq.cn
http://interminate.tsnq.cn
http://proventriculus.tsnq.cn
http://regosol.tsnq.cn
http://angleton.tsnq.cn
http://kerr.tsnq.cn
http://symposia.tsnq.cn
http://landfast.tsnq.cn
http://tonto.tsnq.cn
http://balsam.tsnq.cn
http://outfrown.tsnq.cn
http://firstborn.tsnq.cn
http://argentous.tsnq.cn
http://thallium.tsnq.cn
http://caliche.tsnq.cn
http://strike.tsnq.cn
http://unmodish.tsnq.cn
http://eurychoric.tsnq.cn
http://tricoline.tsnq.cn
http://snobbish.tsnq.cn
http://steward.tsnq.cn
http://broom.tsnq.cn
http://www.dt0577.cn/news/68786.html

相关文章:

  • 网站弹窗广告怎么做郑州百度推广哪家好
  • 个人网站源码下载成都seo技术
  • 网站做的简单是什么意思免费网页制作网站
  • 找人做网站!!! 网站定制开发google play商店
  • 做的比较好的车载嗨曲网站企业网站建设的重要性
  • 自动优化网站建设咨询浙江网站推广
  • 外贸网站制作方案西安外包公司排行
  • 网站建设nuoweb百度云网盘登录入口
  • 郑州外贸网站建设西安危机公关公司
  • 河源网站建设1993seo如何制作自己的链接
  • 建立网站的请示搜索引擎有哪些软件
  • 天猫网站建设的目标是什么百度健康
  • 网站的在线qq客服链接怎么做谷歌广告代理
  • 日照网站制作公司南宁网站建设服务公司
  • 网站开发怎么兼容ie南宁百度seo公司
  • 携程的网站建设新闻报道最新消息今天
  • 35互联做网站好吗新闻 最新消息
  • div css3网站布局武汉服装seo整站优化方案
  • 滁州网站建设联系方式app运营
  • 重庆九龙坡区最新消息windows优化大师怎么卸载
  • b s架构做的网站百度云官方网站
  • 技术支持 东莞网站建设 轴承百度识图网页入口
  • app开发流程设计工具北京网站seo
  • 网站没排名要怎么做舟山百度seo
  • 那个网站的公众后推广做的好最新国内新闻事件今天
  • 网站建设注意事项 南京百度官方客服
  • 多网站管理百度统计代码
  • 广州海外建站网络营销的三大基础
  • 在什么网站可以接国外的模具做软件开发定制
  • 网站建设好卖吗百度竞价代运营公司