简体   繁体   English

用另一个向量替换向量的一部分

[英]Replace a portion of a vector with another vector

I have a vector of size 20 and a second of size 5. I wish to replace elements 11-15 in the first vector with the second vector. 我有一个大小为20的矢量和一个大小为5的矢量。我希望用第二个矢量替换第一个矢量中的元素11-15。 I can do this by deleting those elements from the first vector and inserting the second vector. 我可以通过从第一个向量中删除这些元素并插入第二个向量来实现。 Is there another way to do this, perhaps by using assign? 有没有其他方法可以做到这一点,也许是通过使用assign?

You can use std::copy : 你可以使用std::copy

#include <algorithm> // for std::copy

std::copy(src.begin(), src.end(), dst.begin()+10);

where src is the size 5 vector, and dst is the size 20 vector. 其中src是大小为5的向量, dst是大小为20的向量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM