Inserting into an array of set-s

I want to have many objects of stl::set, able access and insert in each of them.

This could be partly done by vector < set<int> >.
But when I want to insert into these sets,... then my compiler doesn’t accept, since (?) this would change the iterator, making it not valid.

Has somebody a idea how to have many set-s, where I can access each of them and insert, erase, find,... in each of them?
Last edited on
you should be able to do all those thing fine with vector< set<int> > just fine.
something like
1
2
3
vector< set<int> >vector_of_sets;
vector_of_sets.push_back(set());
vector_of_sets[0].insert(5);
for example.
Last edited on
You don't have to declare anything, just change the type to what it should be: set<int>.

chemicus wrote:
Wenn ich sortiere und 2 dieser sets vertauschen will, gibt es auch eine Möglichkeit als ganze Sets umzukopieren

There is no need to copy anything - that's what std::swap is for.
oh, thanks
somehow it works now, doing what I want

but instead of set() in the 2. line I had to deklare before set <int> S; and write there S instead of set(). Is it possible do do without deklaration before?

---------

When I want to sort these sets and want there to exchange 2 of this sets, is there a better possibility that to copy both whole sets?
Is there a more elegant possibility, than to write down separately the number of the sets and the values after which is sorted, then sort. And for Acess to find there out which is the number of the smallest set?
ok .push_back(set<int> ()); works
cool, I didn't know stl::swap, nice function with O(1)

thank you both for helping me
Topic archived. No new replies allowed.