Hello all,
I have a class with a std::set member that I am trying to send to terminal via std::cout. I am trying to achieve this by iterating through the set and dereferencing the iterator. I am unable to achieve this. Anyone able to point me in the right direction please?
Should I be creating a second loop and iterator of type vector<int> and double looping in some way?
Compiler output.
$ make
g++ -c -O -g combo.cpp main.cpp
combo.cpp: In member function ‘int Combo::printCombinations()’:
combo.cpp:25:19: error: no match for ‘operator<<’ in ‘std::cout << it.std::_Rb_tree_const_iterator<_Tp>::operator* [with _Tp = std::vector<int>, std::_Rb_tree_const_iterator<_Tp>::reference = const std::vector<int>&]()’
combo.cpp:25:19: note: candidates are:....... (goes on and on)
my class and comparision function used for my std::set.
class Compare
{
public:
bool operator()(std::vector<int> n1, std::vector<int> n2)
{
if(n1.size() < n2.size() )
return true;
else
return false;
}
};
class Combo{
public:
// constructors
Combo();
Combo(std::vector<int> & vin):numbers(vin){};
// getter setter
int setNumbers(std::vector<int> vin);
std::vector<int> getNumbers();
// the all important
int findCombo(std::vector<int> n_in);
int printCombinations();
private:
std::vector<int> numbers;
std::set<std::vector<int>,Compare> combinations;
};
My function that is causing the problem
int Combo::printCombinations(){
std::set<std::vector<int>,Compare>::iterator it;
for( it = combinations.begin(); it != combinations.end(); it++ ) {
std::cout << *it << std::endl; //<------ This is line 25 where I can't output the values of my set!
}
}
Thanks for any help.