簡體   English   中英

將向量插入向量中

[英]Inserting a vector into a vector of vectors

我正在制作一種使用向量向量的插入排序程序。 我想知道如何將向量插入向量中。

// constructing vector of vectors
vector< vector< int > > v_of_v;
for (int i = 0; i < 3; i++) {
    vector<int> row(2, i*100);
    v_of_v.push_back(row);
}

vector<int> tmp(2, 1);

// predetermined index
index = 2;

v_of_v.insert(index, tmp); // doesnt work

我看到的示例只是遍歷tmp並插入了向量的每個元素,而這並不是我想要的。 我希望能夠插入向量本身,就像push_back一樣。

嘗試這個 :

v_of_v.insert(v_of_v.begin() + index, tmp); 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM