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