title: How to group all anagrams together using a custom comparator function?
body: <p>So, I am developing a logic for grouping all anagrams together using a custom comparator in the sort function which will return true only when the strings are both anagrams which can be easily checked if the sorted versions of the strings are equivalent. I developed the following code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;algorithm&gt;
  bool mycomp (const string &amp;a1, const string &amp;a2);
  #define N 5
  using namespace std;
  
  int main (void)
  {
      int i;
      string arr[50];
      for ( i = 0; i &lt; N; i++ )
      {
          cin&gt;&gt;arr[i];
      }
      sort(arr,arr+N,mycomp);
      for ( i = 0; i &lt; N; i++ )
      {
          cout&lt;&lt;arr[i]&lt;&lt;"\n";
      }
      return 0;
  }
  
  bool mycomp (const string &amp;a1, const string &amp;a2)
  {
      string f1 = sort(a1.begin(),a1.end());
      string f2 = sort(a2.begin(),a2.end());
      return (f1 == f2);
  }
  </code></pre>
  
  <p>Now, this code doesn't compile and shows the error that string cannot be passed in mycomp.. And shows a lot of errors. Also, is my logic correct? Thanks for the help.</p>