[Solved] how to sort 5 strings according to their length and print it out


As suggested you can use sort

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main ()
{
  std::vector<string> vec={"abc","defsf","a","c"}; 
  cout<<"Unsorted string"<<endl;
  for(auto s: vec)
  {
      cout<<s<<" ";
  }
  std::sort(vec.begin(),vec.end(),[](const string& a,const string& b)
    {
        return a.size()<b.size();
    });
 cout<<endl<<"Sorted string"<<endl;
  for(auto s: vec)
  {
      cout<<s<<" ";
  }

  return 0;
}

solved how to sort 5 strings according to their length and print it out