这是代码(查找 2 组的并集):
template <class dtype>
void printSet(dtype data)
{
std::cout<<"\n";
for(auto i = data.begin(); i != data.end(); i++)
{
std::cout<<*i<<" ,";
}
}
int main(int argc, char const *argv[])
{
int arr[] = {1,2,3,4,5};
std::set<long long> a(arr, arr + 5), b(arr, arr + 5), c;
std::vector<long long> v;
b.insert(1000);
printSet(a);
printSet(b);
set_union(a.begin(), a.end(), b.begin(), b.end(), v.begin());
printSet(v);
return 0;
}
这就是我得到的:
1 ,2 ,3 ,4 ,5 ,
[1] 9444 segmentation fault ./a.out
我哪里搞砸了?