嗨,大家好我最近学习了递归,我尝试了很多返回类型,似乎我在过去的一两天里一直在努力解决这个问题.可悲的是,我没有运气.
这个想法是:
码:
string convert(int value, int b){
stringstream s;
//Once the value is 0 or 1 it returns the whole result
if(value ==0 || value ==1)
return s.str();
else
{
//I store the remainder results in the stringstream and call the function again
s<<convert(value/b,b)<<value%b;
}
}
Run Code Online (Sandbox Code Playgroud)