Slicing a vector in C++

后端 未结 4 494
执念已碎
执念已碎 2020-12-29 01:54

Is there an equivalent of list slicing [1:] from Python in C++ with vectors? I simply want to get all but the first element from a vector.

Python\'s lis

4条回答
  •  借酒劲吻你
    2020-12-29 02:40

    This can easily be done using std::vector's copy constructor:

    v2 = std::vector(v1.begin() + 1, v1.end());
    

提交回复
热议问题