将向量插入到向量向量中
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);
相关文章:
- 如何在向量数组中插入元素?
- 将一个向量插入另一个向量的某个位置
- 如何将整数向量值插入字符向量
- C++ 向量插入和迭代器混淆
- 如何将整数向量插入到键中,标准::映射的值
- 当类具有常量时,将对象插入到向量中
- 将向量插入到向量向量中
- C++ std::向量插入两个元素替代算法失败
- C++向量插入元素
- 我们可以使用Back() - 值索引在其上执行向量插入
- C++将向量插入到另一个覆盖向量中
- 如何将向量插入2D矢量的定义位置
- 不能使用 pimpl 习语将用户定义的向量插入到封装的向量中
- C :将向量插入地图
- c++11将向量插入到特定位置
- 向量::插入的异常安全保证是什么?
- C++ 向量插入和读取
- STL 向量插入 - 复制构造函数
- 哪一种方法是更快的向量(插入后排序)或集合
- 标准::向量插入的摊销分析