How to delete (erase) N vector items from specific position in C++

1 Answer

0 votes
#include <iostream>
#include <vector>

using std::cout;
using std::endl;
using std::vector;

int main()
{
	vector<int> vec = { 9, 1, 2, 3, 4, 7, 6, 8 };
	vector<int>::iterator it = vec.begin();

	it += 2;
	vec.erase(it, it + 4);

	for (it = vec.begin(); it != vec.end(); it++)
		cout << ' ' << *it;

	cout << endl;

	return 0;
}


/*
run:

9 1 6 8

*/

 



answered May 17, 2018 by avibootz
edited May 17, 2018 by avibootz

Related questions

1 answer 155 views
1 answer 192 views
2 answers 218 views
1 answer 156 views
2 answers 182 views
2 answers 261 views
...