找回密码
 立即注册
首页 业界区 业界 基于范围的for循环

基于范围的for循环

糙昧邵 6 天前
c++11基于范围的for循环,语法:
  1. for (Type declaration : expression)
  2. {
  3.     // 循环体
  4. }
复制代码
在上面的语法格式中Type declaration表示遍历声明,在遍历过程中,当前被遍历导的元素会被存储到声明的变量declaration中。expression是要遍历的对象,它可以是表达式、容器、数组、初始化列表等。
如下代码:
[code]#include #include using namespace std;int main(void){    vector t{ 1,2,3,4,5,6 };    for (auto value : t){    //第一次遍历        cout

相关推荐

您需要登录后才可以回帖 登录 | 立即注册