# Thread: How to print out all possible subsets using set.h?

1. ## How to print out all possible subsets using set.h?

Hello Everyone,
I have the following problem that I can't solve and would appreciate the help. so the problem is the following.

Write a function that takes a set of distinct Strings as input and prints out all possible subsets.
For example, given input S=("Alice", "Bob", "Dave"), the function should output
(),
("Alice"),
("Bob"),
("Alice","Bob"),
("Dave"),
("Alice", "Dave" ),
("Bob", "Dave" )
("Alice", "Bob", "Dave")

Note that your function may display the subsets in order different from the above. For
simplicity, assume that the size of the set is no larger than 32

Code:
```#include<iostream>
#include<string>
#include<set>
using namespace std;
void DisplayAllSubsets(set<string> S)```
my attempt of the

Code:
```void DisplayAllSubsets(set<string> S){  set<string>::iterator it;
int count = 0; // may need it for finding the amount of combination
for ( it = S.begin(); it != S.end(); ++it)
{ // Not sure how to proceed
}
}```
I have no idea how I could use the set.h tools to output the combination shown in the problem. Any ideas, suggestion, or another container such as vectors that is implemented for this problem would be helpful.

Thank you for your time 2. Have a look at the standard header <algorithm>. While there is nothing there that would do what you need directly there are functions there that could be used. You might need to use some other container type (like vector) that can be reordered by the algorithms. 3. I'd use the fact that there's an isomorphism between the power set of a set size N and the binary strings of length N.
Code:
```Original set: { a, b, c }

000 = "a is not in the subset, b is not in the subset, c is not in the subset" = { }
001 = "a is not in the subset, b is not in the subset, c is in the subset" = { c }
...
101 = "a is in the subset, b is not in the subset, c is in the subset" = { a, c }``` Popular pages Recent additions 