STL vector reserve() and copy()

前端 未结 5 785
情话喂你
情话喂你 2020-12-14 02:51

Greetings,

I am trying to perform a copy from one vector (vec1) to another vector (vec2) using the following 2 abbreviated lines of code (full test app follows):

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-14 03:24

    In my opinion, the simplest way is to use the std::vector::insert method:

    v2.insert(v2.end(), v1.begin(), v1.end());
    

    (see std::vector::insert)

提交回复
热议问题