将元素分配给cpp中的vector

时间:2019-09-08 22:51:47

标签: c++ vector

我想将大小为n的向量复制到大小为2*n的向量中,该向量恰好是向量atemp的两个连续副本。

我正在这样做:

vector<int> temp;
temp.insert(a.begin(), a.begin(), a.end());
temp.insert(a.begin() + n, a.begin(), a.end());

但是它引发了异常。

这是我的whole code

我也尝试过声明尺寸vector<int> temp(2*n),但这仍然给我错误。

1 个答案:

答案 0 :(得分:2)

insert的第一个参数应该是调用该函数的向量的迭代器。也就是说,temp.begin(),而不是a.begin()