Missing a comparision

the following program is not taking last value of the string for comparision
for eg:
expected output
3
batman
bat
apple

actual output
batman
bat

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

bool cmp(string s0,string s1){
if(s0 > s1){
return true;
}
return false;
}

int main() {
string s[100];
int t;
cin>>t;
for(int i=0;i<t;i++){
getline(cin,s[i]);
}
sort(s,s+t,cmp);
for(int i=0;i<t;i++){
cout<<s[i]<<endl;
}
return 0;
}

@vivekshero because you are using getline, this problem is arising. Getline reads till end of line, ie \n character. After you read t, there is a next line character after 3, so that character gets taken as input in s[0] and it stops reading input after that. To avoid this problem, input the \n character before taking input for string array. This problem does not arise with cin because cin ignores whitespaces.
Modified code: https://ide.codingblocks.com/s/604727

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.