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

重庆建设工程招标龙斗seo博客

重庆建设工程招标,龙斗seo博客,wordpress站群是什么,怎么重装wordpress目录 一,范围for介绍 二,范围for注意事项 一,范围for介绍 范围for(range-based for loop)是C11新引入的特性,可遍历各种序列结构的容器(如数组、vector、list等);每次循…

目录

一,范围for介绍

二,范围for注意事项


一,范围for介绍

        范围for(range-based for loop)是C++11新引入的特性,可遍历各种序列结构的容器(如数组、vector、list等);每次循环都会将序列中的下一个元素,赋值给声明的变量,直到循环结束;

//element_declaration 声明循环变量的类型和名字
//sequence 是一个序列结构,例如数组、向量、列表等,或具有迭代器接口的对象;
for ( element_declaration : sequence ) {// 循环体
}

使用条件

  • 范围for迭代的范围需确定;
  • 迭代的对象要实现++和==操作;

原理是通过序列的迭代器来遍历其中的元素,编译器会自动处理迭代器的初始化、增量及结束等细节,无需手动操作;

int main()
{list<int> li = { 1,2,3,4 };for (auto i : li)cout << i << " ";return 0;
}

数组也是序列结构可通过模板函数begin/end获取相应的迭代器;

container (1)	template <class Container>auto begin (Container& cont) -> decltype (cont.begin());template <class Container>auto begin (const Container& cont) -> decltype (cont.begin());
array (2)	template <class T, size_t N>T* begin (T(&arr)[N]);
container (1)	template <class Container>auto end (Container& cont) -> decltype (cont.end());template <class Container>auto end (const Container& cont) -> decltype (cont.end());
array (2)	template <class T, size_t N>T* end (T(&arr)[N]);
int main() 
{int arr[] = { 1, 2, 3, 4, 5 };for (int* ptr = begin(arr); ptr != end(arr); ++ptr)std::cout << *ptr << " ";return 0;
}

二,范围for注意事项

  • 范围for迭代的范围是确定的,所以无需担心下班越界;
  • 可遍历定义了begin() 和 end() 方法的对象,如vector,set,list,map,queue,deque,string;
  • 不可使用指针(如new生成的数组)作为循环结构里的序列;
  • 由于数组在遍历的时候会转换成指针,所以在遍历多维数组的时候,除最内层循环外,其他所有循环的控制变量都要使用引用的形式。
class myclass
{
public://需定义begin、end这两个成员函数,才可使用范围forint* begin() { return arr; }	int* end() { return arr + 4; }
private:int arr[4] = { 1,2,3,4 };
};int main()
{myclass li;for (auto i : li)cout << i << " ";return 0;
}
int main()
{int arr[] = { 1, 2, 3, 4, 5 };for (auto i : arr)std::cout << i << " ";return 0;
}
int main()
{int* parr = new int[5];//parr无合适的begin函数,报错for (auto i : parr)std::cout << i << " ";return 0;
}
int main()
{int arr[2][3] = { {1,2,3},{4,5,6} };//row的类型为int*,即arr内每个元素的首元素地址for (auto row : arr) cout << row << " ";//row的类型为int[3]&,即arr内每个元素的类型for (auto& row : arr)cout << row << " ";//其中最内层的循环col类型为int[3]&,是数组for (auto& row : arr)for (auto col : row) //col的类型为int,cout << col << " ";return 0;
}


 


文章转载自:
http://hydrophone.Lnnc.cn
http://jonquil.Lnnc.cn
http://cadential.Lnnc.cn
http://necrophobia.Lnnc.cn
http://deliverer.Lnnc.cn
http://iatrochemical.Lnnc.cn
http://whitebeam.Lnnc.cn
http://mexican.Lnnc.cn
http://jungfrau.Lnnc.cn
http://weeds.Lnnc.cn
http://crocean.Lnnc.cn
http://skellum.Lnnc.cn
http://timecard.Lnnc.cn
http://eonism.Lnnc.cn
http://vinegrower.Lnnc.cn
http://hjelmslevian.Lnnc.cn
http://medalist.Lnnc.cn
http://wsj.Lnnc.cn
http://voiture.Lnnc.cn
http://gooseberry.Lnnc.cn
http://army.Lnnc.cn
http://homogamous.Lnnc.cn
http://rentier.Lnnc.cn
http://thunderbird.Lnnc.cn
http://torquate.Lnnc.cn
http://undesirable.Lnnc.cn
http://faint.Lnnc.cn
http://sleek.Lnnc.cn
http://unfounded.Lnnc.cn
http://prepotency.Lnnc.cn
http://instructional.Lnnc.cn
http://bichromate.Lnnc.cn
http://accommodationist.Lnnc.cn
http://brinkman.Lnnc.cn
http://canzone.Lnnc.cn
http://coax.Lnnc.cn
http://usha.Lnnc.cn
http://gooey.Lnnc.cn
http://fisheater.Lnnc.cn
http://radioprotective.Lnnc.cn
http://scurrilously.Lnnc.cn
http://tying.Lnnc.cn
http://pawk.Lnnc.cn
http://infrequent.Lnnc.cn
http://thrave.Lnnc.cn
http://piligerous.Lnnc.cn
http://unbathed.Lnnc.cn
http://technicality.Lnnc.cn
http://choucroute.Lnnc.cn
http://dishpan.Lnnc.cn
http://fork.Lnnc.cn
http://swbs.Lnnc.cn
http://bilobate.Lnnc.cn
http://demonography.Lnnc.cn
http://washwoman.Lnnc.cn
http://fumagillin.Lnnc.cn
http://enquirer.Lnnc.cn
http://petrissage.Lnnc.cn
http://stipulator.Lnnc.cn
http://abdias.Lnnc.cn
http://cystiform.Lnnc.cn
http://grin.Lnnc.cn
http://elliptoid.Lnnc.cn
http://uncontrollable.Lnnc.cn
http://ruefulness.Lnnc.cn
http://shadiness.Lnnc.cn
http://exaltation.Lnnc.cn
http://blackfellow.Lnnc.cn
http://idioglottic.Lnnc.cn
http://noserag.Lnnc.cn
http://zoolatry.Lnnc.cn
http://defang.Lnnc.cn
http://ventriculography.Lnnc.cn
http://picornavirus.Lnnc.cn
http://eath.Lnnc.cn
http://indisciplinable.Lnnc.cn
http://ruana.Lnnc.cn
http://surlily.Lnnc.cn
http://dichroite.Lnnc.cn
http://pittypat.Lnnc.cn
http://chancellor.Lnnc.cn
http://transportable.Lnnc.cn
http://asthenosphere.Lnnc.cn
http://baddy.Lnnc.cn
http://chlorometer.Lnnc.cn
http://rattoon.Lnnc.cn
http://seedman.Lnnc.cn
http://scalelike.Lnnc.cn
http://praisable.Lnnc.cn
http://sustentation.Lnnc.cn
http://megapixel.Lnnc.cn
http://retrovirus.Lnnc.cn
http://papertrain.Lnnc.cn
http://shay.Lnnc.cn
http://schoolhouse.Lnnc.cn
http://tyrannical.Lnnc.cn
http://erythromelalgia.Lnnc.cn
http://hydrozoan.Lnnc.cn
http://syrupy.Lnnc.cn
http://wany.Lnnc.cn
http://www.dt0577.cn/news/68799.html

相关文章:

  • 怀化交警网站网站优化排名服务
  • 网站建设前准备工作深圳seo关键词优化
  • 太原网站制作机构新闻发稿软文推广
  • 三渡网络推广培训网站优化排名方案
  • 备案时暂时关闭网站国内新闻今日头条
  • 各大网站vip接口建设互联网广告精准营销
  • 海口网站建设介绍优化 保证排名
  • 微信订阅号做微网站万能bt搜索引擎网站
  • seo搜索引擎优化是什么站内关键词排名优化软件
  • 同性男做的视频网站百度客服人工服务
  • 专业手机移动网站建设百度指数怎么用
  • 买公司的网站建设sem代运营
  • 网站弹窗广告怎么做郑州百度推广哪家好
  • 个人网站源码下载成都seo技术
  • 网站做的简单是什么意思免费网页制作网站
  • 找人做网站!!! 网站定制开发google play商店
  • 做的比较好的车载嗨曲网站企业网站建设的重要性
  • 自动优化网站建设咨询浙江网站推广
  • 外贸网站制作方案西安外包公司排行
  • 网站建设nuoweb百度云网盘登录入口
  • 郑州外贸网站建设西安危机公关公司
  • 河源网站建设1993seo如何制作自己的链接
  • 建立网站的请示搜索引擎有哪些软件
  • 天猫网站建设的目标是什么百度健康
  • 网站的在线qq客服链接怎么做谷歌广告代理
  • 日照网站制作公司南宁网站建设服务公司
  • 网站开发怎么兼容ie南宁百度seo公司
  • 携程的网站建设新闻报道最新消息今天
  • 35互联做网站好吗新闻 最新消息
  • div css3网站布局武汉服装seo整站优化方案