gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:45:07 25 4
gpt4 key购买 nike

我将一个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com