Why does this code gives runtime error :
terminate called after throwing an instance of 'std:length_error' what(): basic_string::_M_create.
while changing the condition in comp function to s1.size() < s2.size()
gives correct answer.
static bool comp(const string& s1,const string& s2){
return s1.size()<=s2.size();
}
int main()
{
int n;
cin>>n;
vector<string> words(n);
for(int i=0;i<n;++i){
cin>>words[i];
}
sort(words.begin(),words.end(),comp);
for(int i=0;i<n;++i){
cout<<words[i]<<" ";
}
return 0;
}