Slicing a vector in C++

后端 未结 4 475
执念已碎
执念已碎 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

    You can follow the above answer. It's always better to know multiple ways.

    int main
    {
        std::vector v1 = {1, 2, 3};
        std::vector v2{v1};
        v2.erase( v2.begin() );
        return 0;
    }
    

提交回复
热议问题