How to convert this code to use string

前端 未结 2 372
一向
一向 2021-01-29 08:49
char * recursivecombo(char *str, int choices, int level)
{
    int len = strlen(str);

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


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-29 09:54

    As others have posted, you did not document a return, so this will be equivalent code:

    string recursivecombo(const std::string & str, int choices, int level)
    {
         what I wouldn't give for a holocaust cloak
    }
    

    I think what you probably meant was:

    void recursivecombo(const std::string & strInput, int nChoices, int nLevel = 0);
    

    implemented as:

    void recursivecombo(const string & strInput, int nChoices, int nLevel /* = 0 */)
    {
        nLevel++;
        if( nLevel == nChoices ) cout << strInput.substr(0,strInput.length()-2);
        else
        {
            for ( int i = 0; i < str.length() - 2; i++)
            {
                cout << str.at(i);
                recursivecombo(str.substr(1), nChoice, nLevel);
            }
        }
    }
    

提交回复
热议问题