How to remove specific value from vector1 and copy the result into vector2 in C++

1 Answer

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

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

int main()
{
	vector<int> vec1 = { 9, 1, 2, 3, 4, 1, 2, 3, 5, 1, 2, 3 };
	vector<int> vec2(12);

	remove_copy(vec1.begin(), vec1.end(), vec2.begin(), 1);

	for (vector<int>::iterator it = vec2.begin(); it != vec2.end(); it++)
		cout << ' ' << *it;

	cout << endl;

	return 0;
}


/*
run:

9 2 3 4 2 3 5 2 3 0 0 0

*/

 



answered May 17, 2018 by avibootz
...