有没有dalao能帮忙解答,为什么此段代码只能输出一个字符,是哪里出了问题
#include<bits/stdc++.h>
using namespace std;
string expand()
{
string ans="",s="";
char c;
int n;
while(cin>>c)
{
if(c=='[')
{
cin>>n;
s=expand();
while(n--)
{
ans+=s;
}
}
else if(c==']')
{
return ans;
}
else
{
return ans+=c;
}
}
}
int main()
{
cout<<expand();
return 0;
}