I think I am not using the iterator properly but I don't see what's wrong with my code:
#include <iostream>
#include <set>
#include <ctime>
#include <cstdlib>
#include <sstream>
int main(){
stringstream s;
set<int> a, b, c;
set<set<int> > d;
set<set<int> >::iterator pos;
srand(time(0));
d.insert(a);
d.insert(b);
d.insert(c);
for (pos = d.begin(); pos != d.end(); pos++){
for (int i=0;i<10;i++){
(*pos).insert(genInt(1,10));
}
s << "\nSet: " << endl << *pos;
}
s << endl;
}
I'm trying to initialize the three sets with random integers, while being part of another set.
The compilation error is in (*pos).insert(genInt(1,10))
:
error: no matching function for call to ‘std::set<int>::insert(int) const’
genInt(1,10)
returns a random integer between 1 and 10.
int genInt(int min, int max){
int tam = max - min + 1;
return ( (rand() % tam) + min);
}