如何将Vector1.end()连接到Vector2.begin();(带out.inter)
How to connect Vector1.end() to Vector2.begin(); ( with out .insert )
我认为我们可以连接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);
相关文章:
- 来自 std::list 的迭代器 .end() 按预期返回"0xcdcdcdcdcdcdcdcd"但 .begin()
- std::map<struct,struct>::find 找不到匹配项,但是如果我循环通过 begin() 到 end(),我在那里看到匹配项
- 调用'begin(int [n])'没有匹配函数
- 为constchar*定义std::begin合法吗
- constexpr begin of a std::array
- remove(str.begin(), str.end(), );无法正常工作(我正在使用视觉工作室 2012)
- 了解向量中的 .begin 和 .end
- 混淆 Begin() 方法作为参数
- std::ranges::begin 和 std::begin 有什么区别?
- C++ const char with .begin() and .end()
- 有没有函数可以在擦除 c++ 中获取 deque.begin() 的 int 值?
- 为什么 string::begin() 在即时窗口中输出整个字符串
- 如果没有重新散列,为什么 unordered_set::begin() 会改变?
- 为什么 std::find( s.begin(), s.end(), val ) 比集合 s 的 s.find(val) 慢 1000 倍<int>?
- begin() 在 C++17 年被制作为 constexpr 但在 C++14 年成为 cbegin() 吗?
- 如何使用vector.begin()和vector.end()遍历矩阵?
- 递减 std::vector::begin 是否未定义,即使它从未被使用过?
- std::begin-类型特征中未考虑用户定义的重载
- 当从成员类调用封装的std::begin时,程序崩溃
- 如何将Vector1.end()连接到Vector2.begin();(带out.inter)