繁体   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