best way to read a string inside while loop

a little problem guys,
suppose my code is like :
while(t–)
{
cin>>s;
//then some string manipulation
//then output
}
but if i input 5 test cases ,it takes only four strings but never 5.i checked and found out that it always skips the first test case…how to solve the problem…i even tried gets,fgets but the same result…please help…

while scanning t when you hit enter it consider it as character, so what i always do is
scanf("%d\n",&t);
then it will run fine. always end %d with a new line…

1 Like

Can you give the complete code snippet you are using . It is difficult to tell without that .

Use like this

while(t)
{
cin>>s; //then some string manipulation //then output
t--;
}
//