Compress string

This shows compilation error. why? please correct me.

code: https://ide.codingblocks.com/s/317375

you are trying to access ith character of the string sto while you havent initialized it so instead use += which would append the given character at the back. moreover your logic is wrong answer for aaabbbaaa would be a3b3a3 but by your logic it would be a6b3,
easiest way to implement is to keep the current count and as the character changes then print the character followed by count no need to store everything in string
Code for reference purpose:

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.