String compression

#include
using namespace std;

string compression(string s)
{
int l=s.length();
string ans;
char temp;
int cnt=1;
for(int i=0;i<l;i++)
{
if(s[i]==s[i+1])
{
temp=s[i];
cnt++;
}
else if(cnt>1)
{
ans+=temp;
ans+=cnt+‘0’;
cnt=1;

    }
    else
    {
        ans+=s[i];
        ans+=cnt+'0';
    }
}
return ans;

}

int main()
{

string s;
cin>>s;
cout<<compression(s);

return 0;

}

what’s wrong in my code ! ! failing only one test case!!

Save your code on ide.codingblocks.com and then share its link.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.