I have a set<string>
from "one", "two", and "three".
How can I get all pairs from it?
- one - two
- one - three
- two - three
I have a set<string>
from "one", "two", and "three".
How can I get all pairs from it?
Use a two-level loop:
// Loop over all members.
for (set<string>::iterator j = s.begin(); j != s.end(); ++j)
{
// Loop over all members up to, but excluding, the current outer-loop member.
for (set<string>::iterator i = s.begin(); i != j; ++i)
{
do_something_with(*i, *j);
}
}