#include<iostream>
#include<cstdlib>
#include<set>
#include<algorithm>
usingnamespace std;
int main()
{
set<int> first;
set<int> res;
set<int> second;
set<int>:: iterator it;
int size;
cout<<"\n enter no of elements of first set: ";
cin>>size;
for(int i=1;i<=size;i++)
{
first.insert(rand()%100);
}
it=first.begin();
cout<<"\n elements of first set:\n ";
while(it!=first.end())
{
cout<<*it<<" ";
it++;
}
cout<<"\n enter no of elements of second set: ";
cin>>size;
for(int i=1;i<=size;i++)
{
second.insert(rand()%100);
}
cout<<"\n elements of second set: \n";
it=second.begin();
while(it!=second.end())
{
cout<<*it<<" ";
it++;
}
//cout<<"\n union of two sets are :\n ";
return 0;
}
I'm not sure if std::set_union works with std::set. Instead you can just insert all the elements from the two set in another set and you will have the union.