How to remove element from specific position (index) in vector with C++

1 Answer

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

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

int main()
{
	vector<int> vec{ 1, 2, 3, 4, 5};

	vec.erase(vec.begin() + 1);

	for (int val : vec)
		cout << val << " ";
	
	cout << endl;

	return 0;
}

/*
run:

1 3 4 5

*/

 



answered May 1, 2018 by avibootz

Related questions

1 answer 200 views
1 answer 176 views
1 answer 168 views
1 answer 167 views
2 answers 181 views
1 answer 160 views
1 answer 97 views
...