从C ++ std :: vector中删除第i个项目 [英] Remove ith item from a C++ std::vector

查看:700
本文介绍了从C ++ std :: vector中删除第i个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从 std :: vector 中删除​​第i个项目?

How do I remove the ith item from a std::vector?

我知道我想删除第ith个元素。我有 int我;和std :: vector< process> pList; ,其中 process 是一个结构。我想做一些等效的事情:

I know I want to delete the ith element. I have int i; and std::vector<process> pList; where process is a struct. I want to do something equivalent to the following:

pList.remove(i);


推荐答案

pList.erase(pList.begin()+i);

删除索引为i的元素。

To remove element with index i.

这篇关于从C ++ std :: vector中删除第i个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆