繁体   English   中英

擦除std :: vector的范围?

[英]Erase range from a std::vector?

如果我的std::vector有100个元素,而我只想保留前10个元素并删除其余元素,那么有一种方便的方法吗?

是的,有一个擦除函数,它接受第一个和最后一个参数。

v.erase(v.begin() + 10, v.end());
vec.resize(10); // drops the rest (capacity remains the same)
theVector.erase(theVector.begin() + 10, theVector.begin() + 100);

vec.erase(vec.begin() + 10, vec.begin() + 100);

暂无
暂无

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

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