0
我的目标是从C++的特定位置插入vector
到另一个vector
。 实施例:C++在特定位置的其他向量中插入向量
std::vector<int> a = {1, 2, 3};
std::vector<int> b = {4, 5, 6};
int position = 1;
输出:1,4,5,6,2,3
我的目标是从C++的特定位置插入vector
到另一个vector
。 实施例:C++在特定位置的其他向量中插入向量
std::vector<int> a = {1, 2, 3};
std::vector<int> b = {4, 5, 6};
int position = 1;
输出:1,4,5,6,2,3
这很容易:
vector<int> a = {1, 2, 3};
vector<int> b = {4, 5, 6};
int position = 1;
a.insert(a.begin()+position,b.begin(),b.end());
我们可以很容易地通过insert功能做到这一点。
std::vector<int> a = {1, 2, 3};
std::vector<int> b = {4, 5, 6};
auto it = a.begin();
int position = 1;
a.insert(it+position, b.begin(), b.end());
你*看过* std :: vector'类的文档吗?因为信息*在那里* .... – DevSolar