如何将Vector1.end()连接到Vector2.begin();(带out.inter)

How to connect Vector1.end() to Vector2.begin(); ( with out .insert )

本文关键字:begin inter out Vector2 连接 Vector1 end      更新时间:2023-10-16

我认为我们可以连接VEC1的末尾和VEC2的开头,但如何连接??

示例

VEC1:(VEC1.begin())->'H'->'A'->'P'->'P'->'Y'->(VEC1.end)

VEC2:(VEC2.begin())->'1'->'2'->'3'->'4'->(VEC2.end)

//VEC1.insert():但这意味着每次O(n)时我们都会push_back()

VEC1=HAPPY1234

VEC2=1234

所以它必须像O(2)一样

VEC1:(VEC1.begin())->'H'->'A'->'P'->'P'->'Y'->(VEC1.end)

…………..___________________ |………|。

…………..|……….._____________ |。

…………..|。

VEC2:(VEC2.begin())->'1'->'2'->'3'->'4'->(VEC2.end)

…………..|。

…………__________________________________。

VEC1=HAPPY1234

VEC2=空;(空)

请告诉我如何通过地址或其他方式连接2个向量;

我知道您希望将vec2的内容移动到vec1的末尾,但不进行任何复制。您可以使用std::move:

#include <utility>
std::size_t size = a.size();
a.resize(size + b.size());
std::move(b.begin(), b.end(), a.begin() + size);