title: How to find Max value of second element of std::pair in std::vector?
body: <p>I have vector of pairs in this order {{label, probability},{label, probability}}. I want to get the pair which has the maximum value of probability. Here's my attempt to accomplish that, but instead of getting the max value of probability, it returns the max value of the label string. e.g. label dog is the largest value because of alphabet order. </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;string&gt;
  #include &lt;algorithm&gt;
  
  int main()
  {
      std::vector&lt;std::pair&lt;std::string, float&gt;&gt; pairs;
      pairs = {{"apple",34.785}, {"banana",67.8467}, {"dog", 13.476}, {"cat",56.486}};
  
      const auto p = max_element(pairs.begin(), pairs.end());
      auto label = p-&gt;first;
      auto prob = p-&gt;second;
  
      std::cout&lt;&lt;label&lt;&lt;" "&lt;&lt;prob;
  }
  </code></pre>
  
  <p>Output : <code>dog 13.476</code></p>