Moving elements from std::vector to another one

前端 未结 4 2154
故里飘歌
故里飘歌 2020-11-27 15:55

How can I move some elements from first vector to second, and the elements will remove from the first?
if I am using std::move, the elements not removed fro

4条回答
  •  我在风中等你
    2020-11-27 16:08

    You can't move elements from one vector to another the way you are thinking about; you will always have to erase the element positions from the first vector.

    If you want to change all the elements from the first vector into the second and vice versa you can use swap.

    If you want to move the same amount of elements between two vectors, you can use swap_ranges

提交回复
热议问题