开发者

How can I combine pairs of elements from a std::set?

I have a set<string> from "one", "two", and "three".

How can I get all p开发者_StackOverflow中文版airs from it?

  • one - two
  • one - three
  • two - three


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);
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜