A
Anirudh Ramachandran
Hi all,
I have a homework problem here, where I have to perform a set
intersection on two sets and use the result elsewhere. I have this
code:
#include <iostream>
#include <iterator>
#include <set>
#include <algorithm>
using namespace std;
int main()
{
int a[] = {1, 2, 3, 4, 5};
int b[] = {3, 4, 5, 6};
set <int> set1(a, a+5), set2(b, b+4);
set_intersection(set1.begin(), set1.end(), set2.begin(),
set2.end(), ostream_iterator<int>(cout, " ")); //I want to do something
else here
return 0;
}
As I said, I dont want to simply output the intersection, but store the
result in an array. The SGI stl reference doesnt seem to provide any
support for this, and even goes on to say that output iterators cant be
read. How do I do it?
Thanks in advance,
anirudh
I have a homework problem here, where I have to perform a set
intersection on two sets and use the result elsewhere. I have this
code:
#include <iostream>
#include <iterator>
#include <set>
#include <algorithm>
using namespace std;
int main()
{
int a[] = {1, 2, 3, 4, 5};
int b[] = {3, 4, 5, 6};
set <int> set1(a, a+5), set2(b, b+4);
set_intersection(set1.begin(), set1.end(), set2.begin(),
set2.end(), ostream_iterator<int>(cout, " ")); //I want to do something
else here
return 0;
}
As I said, I dont want to simply output the intersection, but store the
result in an array. The SGI stl reference doesnt seem to provide any
support for this, and even goes on to say that output iterators cant be
read. How do I do it?
Thanks in advance,
anirudh