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

手机网站建设网网站正在建设中...

手机网站建设网,网站正在建设中...,潍坊专升本考试地点,网站域名更改近来#xff0c;基本上所有现代编程语言都有一种对一个区间写for循环的便捷方式。最终#xff0c;C也有了相同的概念#xff1b;你可以给循环提供一个容器#xff0c;它帮你迭代。 example: #include iostream #include vector #include map usi…近来基本上所有现代编程语言都有一种对一个区间写for循环的便捷方式。最终C也有了相同的概念你可以给循环提供一个容器它帮你迭代。 example: #include iostream #include vector #include map using namespace std;int main() {vectorint num{3, 7, 1, 7, 9};// 修改你正在迭代的容器的值或者你想避免拷贝大的对象for(auto it : num) {cout it endl;}// it 用于捕获vector里面的值for(auto it :num) {cout it endl;}mapint, int num_map; num_map[2] 4;num_map[4] 5;num_map[6] 1;for(auto it : num_map) { cout it.first endl ,second: it.second endl;} }代码分析: 1 #include iostream #include vector #include map using namespace std;int main() {vectorint num{3, 7, 1, 7, 9};// 修改你正在迭代的容器的值或者你想避免拷贝大的对象for(auto it : num) {it;}// it 用于捕获vector里面的值for(auto it :num) {cout it endl;} }结果 Build commands will be stored in build/compile_commands.json build finished successfully (2.229s) 3 7 1 7 9*原因: 迭代器没有取引用的操作,并没有修改原vector的值 #include iostream #include vector #include map using namespace std;int main() {vectorint num{3, 7, 1, 7, 9};// 修改你正在迭代的容器的值或者你想避免拷贝大的对象for(auto it : num) {it;}// it 用于捕获vector里面的值for(auto it :num) {cout it endl;} }Waf: Leaving directory /home/antl417/AI_LB-files/Fattree_DiaoTest_Summary/build Build commands will be stored in build/compile_commands.json build finished successfully (2.246s) 4 8 2 8 102 #include iostream #include vector #include map using namespace std;int main() {mapint, int num_map; num_map[2] 4;num_map[4] 5;num_map[6] 1;for (auto m num_map.begin(); m ! num_map.end(); m){m-second 0.0;}for(auto it : num_map) { cout it.first ,second: it.second endl;} }结果 2,second: 0 4,second: 0 6,second: 0区间遍历的意义 Strings,arrays,和所有的STL容器可以被新的区间迭代方式迭代。但是如果你想让你自己的数据结构使用这个新语法怎么办 为了使这个数据结构可迭代它必须类似于STL迭代器。 这个数据结构必须要有begin和end方法成员方法和独立函数都行这两个方法分别返回开始和结束的迭代器 迭代器支持操作符、!操作符、方法前缀形式成员函数和独立函数都行 就这些实现这五个函数你就可以有一个支持区间迭代的数据结构。因为begin、end可以是非成员函数你甚至可以适配现有数据结构而不用实现STL风格的迭代器。所有你要做的是创建你自己的支持、前缀和!的迭代器并且定义好自己的begin、end。 另外vector的几种遍历方式 #include vector #include iostream #include algorithm // for_eachusing namespace std;struct Point {double x;double y;Point(){x 0;y 0;} };int main() {vectorPoint m_testPoint;m_testPoint.clear();m_testPoint.shrink_to_fit();for (int i 0; i10; i){Point temp;temp.x i*i;temp.y i*i;m_testPoint.push_back(temp);}//第一种遍历方式下标cout 第一种遍历方式下标访问 endl;for (int i 0; im_testPoint.size(); i){cout m_testPoint[i].x m_testPoint[i].y endl;}//第二种遍历方式迭代器cout 第二种遍历方式迭代器访问 endl;for (vectorPoint::iterator iter m_testPoint.begin(); iter ! m_testPoint.end(); iter){cout (*iter).x (*iter).y endl;}//第三种遍历方式auto关键字cout C11,第三种遍历方式auto关键字 endl;for (auto iter m_testPoint.begin(); iter ! m_testPoint.end(); iter){cout (*iter).x (*iter).y endl;}//第四种遍历方式auto关键字的另一种方式cout C11,第四种遍历方式auto关键字 endl;for (auto i : m_testPoint){cout i.x i.y endl;}// 第五种遍历方式for_eachcout C11,第五种遍历方式for_each endl;for_each(m_testPoint.cbegin(), m_testPoint.cend(), [](const auto val) - void { cout val.x val.y endl; });return 0;
http://wiki.neutronadmin.com/news/108494/

相关文章:

  • 泰兴市淘宝网站建设网页制作软件dw还需要什么
  • 南京网站建设电话网站开发服务计入什么科目
  • 淘宝代做网站怎么做淘宝客的跳转网站
  • 做租赁的行业网站网络传媒公司名字
  • 建立个人网站能干二次开发包
  • 互联网科技公司网站免费3d建模软件
  • 高端网站建设合同深圳网站开发哪个好
  • 网站开发所需技能湘潭网站建设公司有哪些
  • 青岛有没有做网站的构建平台还是搭建平台
  • 网站开发谷歌浏览器js不更新网站建设的编程语言
  • 娱乐城网站模板wordpress4.5.3 中文
  • wap网站源码 下载郑州厉害的seo优化顾问
  • 贵州省住房和城乡建设厅查询网站手机聊天app开发
  • 做网站选什么系统wordpress4.9升级失败
  • 网站仿站是啥wordpress媒体默认链接
  • 福田做网站多少钱网络广告营销的典型案例
  • 品牌和网站建设全国响应式网站建设
  • 企业营销型网站建设公司房地产网站怎样建设才能快速盈利
  • 电子通讯录网站建设门户网站 集成 移动app 方案
  • 网站开发行业标准学室内设计要多久能学会
  • 阿里云网站域名申请网站系统升级需要多久
  • 十大招商平台百度seo搜索引擎优化方案
  • 杭州网站建设公司推荐动漫制作专业专科
  • 沾益住房和城乡建设局网站qq是哪个公司创办的
  • 微信公众号服务号网站开发流程图网站设计建设有限公司
  • 建设一个连接的网站银川网站开发
  • 大型网站集群怎么做学做ps的网站
  • dede网站栏目管理如何建设公司网站公司网站
  • 重庆建网站价格表湖北海厦建设有限公司网站
  • 安康 住房城乡建设部网站网站设计实验报告内容与步骤