所在的位置: C++ >> C++市场 >> C11新特性之for循环

C11新特性之for循环

免费多视频网站vip会员账号 http://www.prcgoogle.com/zonghe/guonei/2021/0913/6010.html

编过程的小伙伴应该对for不陌生吧,for循环是最简单的分支语句,经常使用到它,那么C++新特性对for做了哪些优化呢?接下来就跟着小编步伐,一起来了解新的for循环用法。

在C++11之前,我们使用for循环来遍历数组、容器的时候的语法是这样的:

for(表达式1;表达式2;表达式3){//循环体}

下面举几个例子来演示一下for循环遍历:

#includeQCoreApplication#includeiostream#includevectorusingnamespacestd;intmain(intargc,char*argv[]){QCoreApplicationa(argc,argv);//遍历整型数组intserven_array[10]={1,2,3,4,5,6,7,8,9,0};for(inti=0;isizeof(serven_array)/sizeof(serven_array[0]);i++){coutserven_array[i]"";}coutendl;//遍历字符数组charserven_char[]="


转载请注明:http://www.aierlanlan.com/rzdk/497.html