C++11: Range-looping vector from the second element?

前端 未结 2 423
天命终不由人
天命终不由人 2020-12-19 04:27

I have a std::vector v; (initialized). How can I use the range-for loop for accessing all elements except the first one (on index zero). For

2条回答
  •  悲哀的现实
    2020-12-19 04:58

    Until ranges make it into the standard library, you won't get any better than a vanilla for loop in plain C++ :

    for(auto i = begin(v) + 1, e = end(v); i !=e; ++i)
        // Do something with *i
    

提交回复
热议问题