: 나는 무작위로 3 개 세트 초기화하기 위해 노력하고있어컴파일 오류 사용하여 반복자 내가 제대로 반복자를 사용하지 오전하지만 난 내 코드와 뭐가 잘못 표시되지 않습니다 생각 <set<int>>
#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;
}
다른 세트의 일부인 정수입니다.
컴파일 오류에 (*pos).insert(genInt(1,10))
:
error: no matching function for call to ‘std::set<int>::insert(int) const’
genInt(1,10)
랜덤 정수
int genInt(int min, int max){
int tam = max - min + 1;
return ((rand() % tam) + min);
}
1 내지 10