My code is giving the error in first code but second one is running without any error "terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc Aborted (core dumped)" //First
#include<bits/stdc++.h>
using namespace std;
int main()
{
//code
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
string res;
while(n)
{
res.push_back((n%26) + 'A');
n=n/26;
n-=1;
}
reverse(res.begin(),res.end());
cout<<res<<endl;
}
return 0;
}
The second code is as follow which is showing no error can anyone tell me why this error is there
while(n)
{
n-=1;
res.push_back((n%26) + 'A');
n=n/26;
}