Strings compression doubt

Question:https://hack.codingblocks.com/contests/c/509/1371
Solution:https://ide.codingblocks.com/s/38961

I am able to pass the testcases but I wanna ask

  1. what happens when cin.get() after reading characters reaches end of input(after ‘s’) e.g aaabbccds because
  2. when i tried to trace it through debugger ch was storing this value -1 ‘\377’ what is that?
  3. is there other way than this (ch!=-1) to detect end of input?

Hey Tushar, when you do not provide any value in input and still calls cin.get() it automatically reads garbage input until it gets a ‘\n’ (which is default terminator).

Plz explain the 2 and 3 point as well

Can you please elaborate you point 2 again, i didn’t get what you are asking.
And you can take a string input by using cin>> . Also you can detect the end of input by checking if ch==’\n’
(i.e char for new line).