error at cout

I want to obtain all the subsets of a set . I tried this code but I have an error at "cout<<subset[i]" and i can't figure out what is wrong.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

  void displaySubSet(const vector<int> &set) {
    
    vector<vector<int>> subset;
    
   for(int i=0;i<set.size();i++){
        for(int j=0;j<subset.size();j++)
        ssubset[j].push_back(set[i]);
        for(int j=0;j<subset.size();j++)
        subset.push_back(subset[j]);
        cout<<subset[i]<<endl;
    }


}
I have an error at "cout<<subset[i]"

What is the error? Please post the full text of the error.

BTW, you have a spelling error on line 8 (assuming that's not a global that you have not shown).

Line 11: subset is a vector of vectors. Therefore, subset[i] is a vector. std::vector does not overload the << operator, therefore cout does not know how to format a vector.
Last edited on
error: cannot bind 'std::ostream { aka std:: basic_ostream<char>)' lvalue to 'std::basic_ostream<char>&&
error: initializing argument 1 of 'std::basic_ostream<CharT, _Traits>& std::operator<<std:: basic_ostream<harT, _Trats>>&&, const_ Tp&) [with _CharT= char; _Traits= std:: char_traits <char>; _Tp=std::vector<int>}'
how I have to make another two for ?
Your subset is a vector<vector<int>> you can only print a single element of your vector, not an entire vector, unless you overload the insertion operator<< to print a vector<int>.

To print a single element you will need something like subset[i][j].

Topic archived. No new replies allowed.