如何将此代码转换为使用字符串

nod*_*nja -1 c++ string char

char * recursivecombo(char *str, int choices, int level)
{
    int len = strlen(str);

    level++;
    if( level == choices)
    {   
            for (int i = 0; i < len -2; i++)

            {   

                   printf("%c", str[i]) ;
            }   
    }   
    else
    {   
        for (int i = 0; i < len - 2; i++)
        {   
                printf("%c",str[i]);
                recursivecombo(str.substr(1), level);

        }   
    }   
}
Run Code Online (Sandbox Code Playgroud)

我想使用字符串而不是 char*。

Dum*_*der 5

std::string recursivecombo(const std::string& str, int choices, int level)
{
    level++;
    for (int i = 0; i < str.length() -2; ++i)
    {
        cout<<str.at(i) ;
        if( level != choices)
            recursivecombo(str.substr(1),8,/*Missing choce*/ level);
    }  
/*Missing return value*/ 
}
Run Code Online (Sandbox Code Playgroud)

这只是一个使用字符串的模型。你的函数的一些问题

1)你的返回值在哪里

2)如果你打算使用字符串使用cout,而不是printf,如果是C++

3)使用前缀++。