c++ - 在 2dim vector 中插入一个值?

标签 c++ vector

我将 2dim 数组复制到 vector 中,如下所示

vector< vector<int>> path2;
 vector<int> temp; // For simplicity
 for (int x = 0; x <= 1; x++)
{temp.clear();
    for (int y = 0; y < 4; y++)
    {
        temp.push_back(path1[x][y]);
    }
    path2.push_back(temp);

}

现在我想在其第二维中插入一个值,我该怎么做?(我知道如何在 1 个暗 vector 中使用 inser())

例如

path2[0][6,0,2,6]
path2[1][6,1,3,6]

现在如何在 1 和 3 之间插入 4 ?

提前谢谢

最佳答案

使用std::vector::insert

path2[1].insert(path2[1].begin()+2, 4 );

关于c++ - 在 2dim vector 中插入一个值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22897535/

相关文章:

c++ - 使用编译器安装库

c++ - vector<char> 优于字符串的好处?

vector - 将向量连接到普通关键字或关键字向量的惯用方法

c++ - 在 C++ 中使用指向动态分配对象的指针 vector 时如何避免内存泄漏?

c++ - cpp 二维 vector 参数(大小,?)?

python - OpenCV VideoCapture 设备索引/设备号

c++ - 在 C++11 中,使用 std::unique_lock<std::mutex> 作为类成员是否明智(甚至安全)?如果是这样,是否有任何指导方针?

c++ - 通过删除点链接和重复的斜线规范化 Unix 文件路径

c++ - 彩票中奖概率 C++

c++ - 在 std::vector::resize 和 std::vector::push_back 中摊销