小编bha*_*anu的帖子

在嵌套的基于范围的for循环中使用auto(用于迭代)

目前我已经开始使用auto关键字.我对此有一些疑问:

如果我需要遍历vector我:

vector<int>v; 

for(auto it : v){    

   cout << it <<endl; 

}
Run Code Online (Sandbox Code Playgroud)

但是假设我需要做以下事情:

vector<int>v;

for(auto it:v){    
   for(auto jt:X){

   //where X is next position of it's position
   //What I mean is if it is currently at 2nd position then 
   //jt iterator will start from 3rd position

   }    
}
Run Code Online (Sandbox Code Playgroud)

我完全不知道该怎么做.请建议适当的方法.提前谢谢.

c++ iterator vector auto c++11

5
推荐指数
1
解决办法
1377
查看次数

标签 统计

auto ×1

c++ ×1

c++11 ×1

iterator ×1

vector ×1