如下代码ac,但当读入的字符串中没有']'时为什么会正常执行return str?
#include<iostream>
#include<string>
#define ll long long
using namespace std;
string solve(){
int n;
char ch;
string str="",temp="";
while(cin>>ch){
if(ch=='['){
cin>>n;
temp=solve();
while(n--)str+=temp;
}
else if(ch==']'){
return str;
}
else str+=ch;
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cout<<solve();
return 0;
}