请问各位在c++如何运用递归函数将int类型转化成string类型 不用库里面inttostring转换的函数
1条回答 默认 最新
快乐鹦鹉 2022-03-10 17:22关注将整数不断除以10,如果结果不为0,则继续调用递归,最后将余数加上'0'变成字符后加入字符串
#include <iostream> #include <string> using namespace std; void fun(int n,string &s) { if(n/10>0) fun(n/10,s); s += n%10+'0'; } int main() { int n; string s; cin>>n; fun(n,s); cout<<s<<endl; return 0; }本回答被题主选为最佳回答 , 对您是否有帮助呢?评论 打赏 举报 编辑记录解决 1无用