Compressing strings code

i am taking an array of size 256 for all possible characters. i am incrementing the value at the index of the character. then i am printing the charcter followed by the value of array at that index. after printing i am setting it as zero so that it is not printed again
#include
#include
#include
using namespace std;
int main() {
int a[256]={0};
string s; cin>>s;
char x;
for (int i=0;i<s.length();i++)
{
x=s.at(i);
a[(int)x]++;
}
int y;
for (int i=0;i<s.length();i++)
{
x=s.at(i);
y=(int)x;
if(a[y]==0) continue;
cout<<x<<a[y];
a[y]=0;

}
return 0;

}

you just need to do this nothing else like setting it to zero
while(i<str.size())
{
char ch=str[i];
int count=0;
cout<<str[i];
while(ch==str[i])
{
count++;
i++;
}

 cout<<count;

}

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.