Problem with set_union

I'm trying to union two sets (in a vector).

setA contains a, b.
setB contains a, c.

After union, result is supposed to contain a, b, c.
However, the program is not working, it is having some kind of debug error.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
	vector<char> setA;
	vector<char> setB;
	vector<char> result;
	vector<char>::iterator it;

	setA.push_back('a');
	setA.push_back('b');
	setB.push_back('a');
	setB.push_back('c');

	it = set_union(setA.begin(), setA.end(), setB.begin(), setB.end(), result.begin());

	for (int i = 0; i < result.size(); i++)
	{
		cout << result[i] << " ";
	}

	system("PAUSE");
}


Does anyone know what the problem is?
Nevermind, solved it with resizing
Yep, an alternetive is to use an inserter iterator.
Topic archived. No new replies allowed.