for中带有冒号

在C++11中经常有如下的写法

for (int &n : nums) n++;//nums是一个数组,或者其他的容器

for循环的含义等同于for (int i=0; i<nums.size(); i++),其中n=nums[i],注意在n前面加入引用符号,这样数组中的值才是可以更改的,如果没有加入,则数组是可读的,不能更改,具体见这篇文章https://blog.csdn.net/hailong0715/article/details/54172848

猜你喜欢

转载自blog.csdn.net/qq_34489443/article/details/84066678