sort string according to length in c++
#include <bits/stdc++.h>
using namespace std;
// Function to check the small string
bool compare(string &s1,string &s2)
{
return s1.size() < s2.size();
}
// Driver function
int main()
{
string arr[] = {"GeeksforGeeks", "I", "from", "am"};
int n = sizeof(arr)/sizeof(arr[0]);
// Function to perform sorting
sort(arr, arr+n, compare);
return 0;
}