I need to find the 'length' of union between 2 vectors.
The code I have is
vector<int> v1,v2; vector<int> unionsetv; vector<int>::iterator it; v1.push_back(1);v1.push_back(2);v1.push_back(3); v2.push_back(3);v2.push_back(2);v2.push_back(4); it = set_union(v1.begin(),v1.end(),v2.begin(),v2.end(),back_inserter(unionsetv)); cout << unionsetv.size()<< " "; cout << int(it - unionsetv.begin())<< " " ;
I could not get this to work and I have used the set_union in the same way as given in the cplusplus.com reference. If I remove the iterator 'it' then I get the entire size of the unionsetv vector (here this is 6) but this will have zero values in it (obtained during union). What I need is a union where the length of union is 4 and not 6. In any case, I did not get my code to run. Please help me identify what I have overlooked.