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 223 views
1 answer 189 views
1 answer 187 views
1 answer 190 views
2 answers 222 views
1 answer 184 views
1 answer 113 views
...