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.
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
int main()
{
std::vector<std::pair<std::string, float>> 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->first;
auto prob = p->second;
std::cout<<label<<" "<<prob;
}
Output : dog 13.476