2017-05-04 104 views
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

+1

你*看过* std :: vector'类的文档吗?因为信息*在那里* .... – DevSolar

回答

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()); 
0

我们可以很容易地通过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());