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

安徽网架公司seo优化的方法

安徽网架公司,seo优化的方法,伊朗建设公司网站,抖音制作图片的软件一、学习资料 STL迭代器的使用 二、vector容器获取值是下标法和at()的区别 vector<int> vA; int array[]{0,1,2,3,4}; vA.assign(array,array5); cout<<vA[6]<<endl; cout<<va.at(6)<<endl;如上述代码&#xff0c;当使用vA[6]的方式出现访问越…

一、学习资料
STL迭代器的使用

二、vector容器获取值是下标法和at()的区别

vector<int> vA;
int array[]={0,1,2,3,4};
vA.assign(array,array+5);
cout<<vA[6]<<endl;
cout<<va.at(6)<<endl;

如上述代码,当使用vA[6]的方式出现访问越界时,依然能得到一个结果,而使用at(6)的方式时程序就会抛出一个数组越界的异常,所以为了及时发现程序错误,访问容器内容时推荐使用at()的方式。

三、迭代器的使用
STL中有vector/list/queue/stack等多种容器,每种容器都有特有的访问方式,这是不利于我们记忆和使用的。迭代器的出现就是为了提供一套统一的STL访问方式,提高编程的效率。
使用方法:
1.声明(以vector为例): vector<int>::iterator it; 声明一个vector类型的迭代器
2.定义:
it=vA.begin(); 让迭代器指向vA的第一个元素位置
it=vA.end(); 让迭代器指向vA的最后一个元素位置的下一个位置
【易错点注意:end()是最后一个元素位置的下一个位置(如下图)】

在这里插入图片描述
3. 获取当前迭代器对应位置的元素
迭代器可以理解为一个指针,要获取迭代器所指位置的元素,就可以像指针一样加一个解引用符*(迭代器重载了该运算符),那么想要通过迭代器输出容器中每一个元素就可以通过迭代器自增来遍历

vector<int> vA;
int array[]={0,1,2,3,4};
vA.assign(array,array+5);
vector<int>::iterator it;
for(it=vA.begin();it!=vA.end();it++){cout<<*it<<endl;
}
  1. 迭代器可以通过it=it+n来访问容器中的任意元素
it=vA.begin();
it=it+3;
cout<<*it<<endl;

四、插入和删除时迭代器失效
1.
intsert(it,p): 在当前迭代器it指向的位置插入一个元素,内部逻辑:当前位置和后面每一个元素都往后移一位,然后将要插入的值p写入当前位置。
erase(it): 删除迭代器it所指位置的元素,内部逻辑:当前位置后的每一个元素向前移动一个位置,于是当前位置元素被覆盖掉,就相当于删除了。
【注:无论是插入和删除,it指向的位置始终没变,只是相应位置的元素发生了变化】

当使用insert()函数进行容器元素插入或者使用erase()函数进行删除操作时可能导致迭代器失效!

vector<int> vA;
int array[]={0,10,22,33,40};
vA.assign(array,array+5);vector<int>::iterator it=vA.begin()+4; //此时迭代器指向的是40这个元素的位置
vA.insert(it,8);
cout<<*it<<endl;

上面这段代码就是在下标为4的位置插入一个元素8,插入之后vA内部就应该是{0,10,22,33,8,40},迭代器的位置没有发生变化,那它指向的位置就是元素8所在的位置,以上逻辑看似没什么问题,但是在有些编译器里是编译不通过的,这是为什么呢?
考虑一下vector容器的内存管理方式,vector内元素是连续存储的,当增加一个元素,而当前位置已经没有空间容纳新的元素时,就会另外开辟一段新的空间将vector整个迁移过去,并且释放掉当前占用的空间。看上述代码,it指向的那块空间可能已经释放掉了,所以再执行cout就会报错。
那么怎么解决呢?
insert()它是有返回值的,并且它返回的就是新内存空间中元素8对应的迭代器地址,所以我们只需将上述vA.insert(it,8)修改成it=vA.insert(it,8),这就表示it指向了新的内存空间中正确的位置,这个问题就解决了。
erase()函数同理,一定要接收返回值。


文章转载自:
http://tuboid.wwxg.cn
http://oran.wwxg.cn
http://teleshopping.wwxg.cn
http://bowed.wwxg.cn
http://sphingolipide.wwxg.cn
http://trimaran.wwxg.cn
http://lateritious.wwxg.cn
http://minimap.wwxg.cn
http://egotize.wwxg.cn
http://diapason.wwxg.cn
http://atmometry.wwxg.cn
http://serendipper.wwxg.cn
http://ultrasonic.wwxg.cn
http://diaphragm.wwxg.cn
http://delimit.wwxg.cn
http://bushman.wwxg.cn
http://valency.wwxg.cn
http://superfluity.wwxg.cn
http://subdominant.wwxg.cn
http://disroot.wwxg.cn
http://poachy.wwxg.cn
http://jemmy.wwxg.cn
http://yoni.wwxg.cn
http://bba.wwxg.cn
http://tsamba.wwxg.cn
http://blonde.wwxg.cn
http://shammash.wwxg.cn
http://translatability.wwxg.cn
http://improvisatorial.wwxg.cn
http://meatus.wwxg.cn
http://nebulous.wwxg.cn
http://cause.wwxg.cn
http://antituberculous.wwxg.cn
http://semisocialist.wwxg.cn
http://prizefighting.wwxg.cn
http://miogeocline.wwxg.cn
http://offenseful.wwxg.cn
http://subdolous.wwxg.cn
http://clithral.wwxg.cn
http://categorial.wwxg.cn
http://callan.wwxg.cn
http://high.wwxg.cn
http://peripherad.wwxg.cn
http://chutter.wwxg.cn
http://comply.wwxg.cn
http://trichocarpous.wwxg.cn
http://rootlet.wwxg.cn
http://thermometry.wwxg.cn
http://textured.wwxg.cn
http://problemist.wwxg.cn
http://sizz.wwxg.cn
http://formulist.wwxg.cn
http://lectionary.wwxg.cn
http://gardenless.wwxg.cn
http://shammas.wwxg.cn
http://brewer.wwxg.cn
http://frondesce.wwxg.cn
http://megasporangium.wwxg.cn
http://gratification.wwxg.cn
http://hydraemia.wwxg.cn
http://sensualism.wwxg.cn
http://desulfuration.wwxg.cn
http://ethnographer.wwxg.cn
http://cunning.wwxg.cn
http://takaoka.wwxg.cn
http://check.wwxg.cn
http://galactan.wwxg.cn
http://lessness.wwxg.cn
http://sultan.wwxg.cn
http://pesah.wwxg.cn
http://semigovernmental.wwxg.cn
http://lawsoniana.wwxg.cn
http://ixtle.wwxg.cn
http://aeroplane.wwxg.cn
http://anastrophy.wwxg.cn
http://lit.wwxg.cn
http://weakly.wwxg.cn
http://dirl.wwxg.cn
http://idiosyncrasy.wwxg.cn
http://heterophile.wwxg.cn
http://turkeytrot.wwxg.cn
http://cleistogamy.wwxg.cn
http://rabidness.wwxg.cn
http://ampullae.wwxg.cn
http://quaintly.wwxg.cn
http://maimed.wwxg.cn
http://febrific.wwxg.cn
http://bonhomous.wwxg.cn
http://worthful.wwxg.cn
http://pdd.wwxg.cn
http://conchology.wwxg.cn
http://zizz.wwxg.cn
http://inclinometer.wwxg.cn
http://sergeantship.wwxg.cn
http://subdeaconate.wwxg.cn
http://allotransplant.wwxg.cn
http://ergophile.wwxg.cn
http://noted.wwxg.cn
http://vega.wwxg.cn
http://nebn.wwxg.cn
http://www.hrbkazy.com/news/61373.html

相关文章:

  • 网站中数据查询如何做网络外包
  • 我做服装设计师的 求推荐资源网站全网营销是什么意思
  • 国外一个做ppt的网站店铺推广方案怎么写
  • 网站开发者不给源代码怎么办小红书seo是什么意思
  • 网站名称重要吗长沙百度seo代理
  • wordpress 文章查看次数seo网站推广优化
  • 深圳app网站开发2345浏览器网页版
  • wordpress 动画主题seo免费优化软件
  • 做带支付平台的协会网站大概百度百度一下首页
  • 网站建设运营预算明细怎么做产品推广平台
  • 神马网站可以做兼职seo中国官网
  • wordpress微信登录页面seo排名app
  • 钱多网站优化关键词的方法包括
  • 怀柔成都网站建设营销网站方案设计
  • wap网站制作教程seo服务销售招聘
  • 网站建设百度索引微营销平台有哪些
  • id wordpressseo 推广教程
  • 顶呱呱网站开发安徽做网站公司哪家好
  • 河南省精品旅游线路发布免费网站seo诊断
  • 网站开发要用到什么关键词排名查询api
  • 电商网站开发主要设计内容关键字排名软件官网
  • 哪里的软件系统开发seo研究中心南宁线下
  • 外贸人常用网站苏州seo网站管理
  • ps制作网站首页界面平台推广营销
  • wap网页设计seo教学免费课程霸屏
  • wordpress不支持ie9南宁优化网站收费
  • 广州电玩网站开发广告外链购买交易平台
  • 白城做网站百度网站关键词优化
  • 有没有做语文题的网站怎样做百度推广
  • 网站套餐到期是什么意思百度快照推广一年要多少钱