String sort(lexicographical order)

#include
#include
#include
using namespace std;
int main(){
string s[100];
int n;
cin>>n;
cin.ignore();
for(int i=0;i<n;i++){
getline(cin,s[i]);
}
sort(s,s+n);
for(int i=0;i<n;i++){
cout<<s[i]<<endl;
}
}
what changes i should make in this code so that it sorts batman than bat in the givem string

@tishya_goyal hi ,apko apna comparator bnana pdega is trah se sort krne ke lie,here is comparator function isme find function ka use hua hai:
bool myCompare(string a, string b) {
if (a.find(b)==0 || b.find(a)==0)
return a.length() > b.length();
return a < b;
}
pass this comparator as third argument in sort function.Hope you get it :slight_smile: