Test case 2 failled, Please tell the problem in my code

#include<bits/stdc++.h>
using namespace std;

string str_comp(string a)
{
string temp; \Temp string to store new string
int prev=0, curr, count = 1;
char ch ;
stringstream ss;
for(curr=1; curr<a.size(); ++curr)
{
if(a[curr] == a[prev])
{
count++;
}
else
{
ss<<count;
ss>>ch;
temp+=a[prev];
temp+=ch;
prev = curr;
count = 1;
}
}
temp+=a[prev];
ss<<count;
ss>>ch;
temp+=ch;
return temp;
}
int main() {
string str;
string ans;
//Taking the string as input from the user

getline(cin,str);
ans = str_comp(str); //Calling the string compress fun
cout<<ans;
return 0;

}

@babayaga
aaaaaaaaaa
your code giving a1 but ans a10

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.