gpt4 book ai didi

c++从特定位置在其他 vector 中插入 vector

转载 作者:行者123 更新时间:2023-11-27 23:54:22 25 4
gpt4 key购买 nike

我的目标是使用 C++ 从特定位置将 vector 插入到另一个 vector 中。示例:

std::vector<int> a = {1, 2, 3};
std::vector<int> b = {4, 5, 6};
int position = 1;

输出:1、4、5、6、2、3。

最佳答案

很简单:

vector<int> a = {1, 2, 3};
vector<int> b = {4, 5, 6};
int position = 1;
a.insert(a.begin()+position,b.begin(),b.end());

关于c++从特定位置在其他 vector 中插入 vector ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43778036/

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