选择所有元素,但一个带有std :: vector的给定索引的元素?
给定一个std :: vector,例如ints
std :: vector vec {10,20,30}
如何选择除给定索引以外的所有项目,例如int i = 1
结果
std :: vector {10,30}
?
Given a std::vector, for example of ints
std::vector vec{10, 20, 30}
how to select all items except of with given index, for example int i=1
resulting
std::vector {10, 30}
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您只想从原始向量“选择”值,我将创建另一个具有所有新值的向量。
但是,如果您想从原始矢量中删除值,我建议使用vector.erase方法(研究文档)。
If you just want to "select" values from the original vector, I would create another vector with all the new values.
However, if you want to erase values from your original vector I would recommend using the vector.erase method (research the documentation).
这是您可以通过向量和索引的功能,它将在没有该索引元素的情况下返回新向量。
希望这会有所帮助
Here is a function for it where you can pass the vector and index and it will return you the new vector without that index element.
Hope this helps