Post c++ 中字符串中索引的增量

Post increment of index in a string in c++

这是一个函数,它生成给定字符串中具有不同字符组合的所有可能的字符串,并且对于生成的字符串,如果它们的长度等于函数参数中指定的长度return这些字符串在放。 代码 1 工作正常,而代码 2 有一行更改,在连接后更改字符串内的索引(post-增量),但此操作会导致不同的输出。我的想法是,即使我使用 s[i++] 因为 post-increment,comb 字符串也会与 s[i] 的期望值连接,但行为是不同的。任何人都可以帮助解决此行为的正确原因吗?

code 1:
set<string> generate_comb(string s,int len)
{
    set<string> hold;
    int mask = 1<<s.length();
    for(int no=1;no<mask;no++)
    {
        int num = no;
        int i = 0;
        string comb = "";
        while(num)
        {
            if(num&1)
                comb = comb + s[i];
            num = num>>1;
            i++;
        }
        if(comb.length()==len)
            hold.insert(comb);
    }
    return hold;
}

code 2:
set<string> generate_comb(string s,int len)
{
    set<string> hold;
    int mask = 1<<s.length();
    for(int no=1;no<mask;no++)
    {
        int num = no;
        int i = 0;
        string comb = "";
        while(num)
        {
            if(num&1)
                comb = comb + s[i++]; //this line has been changed 
            num = num>>1;
            //i++;
        }
        if(comb.length()==len)
            hold.insert(comb);
    }
    return hold;
}

区别在于if:

if(num&1)
    comb = comb + s[i];
num = num>>1;
i++;

如果条件为真,连接字符串,然后执行其余操作不管条件如何。

if(num&1)
    comb = comb + s[i++];
num = num>>1;

如果条件为真,连接并递增,但如果条件为假不发生递增