title: How to sort a vector of structs based on a vector<string> within the vector to be sorted?
body: <p>What is the best way to alphabetically sort a vector of structures based on the first word in every vector of all the structures in the vector of structures?</p>
  
  <pre><code>struct sentence{
      vector&lt;string&gt; words;
  };
  
  vector&lt;sentence&gt; allSentences;
  </code></pre>
  
  <p>In other words, how to sort allSentences based on words[0]?</p>
  
  <hr>
  
  <p><strong>EDIT:</strong> I used the following solution:</p>
  
  <pre><code>bool cmp(const sentence&amp; lhs, const sentence &amp; rhs)
  {
    return lhs.words[0] &lt; rhs.words[0];
  }
  
  std::sort(allSentences.begin(), allSentences.end(), cmp);
  </code></pre>