Why does this:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
vector<pair<int, string>> list;
int main() {
int one = 1, two = 2, three =3, five =5, six = 6;
string bla = "bla";
list.push_back( pair<int, string>(two, bla));
list.push_back( pair<int, string>(one, bla));
list.push_back( pair<int, string>(two, bla));
list.push_back( pair<int, string>(six, bla));
list.push_back( pair<int, string>(five, bla));
sort(list.begin(), list.end());
for(auto item : list) {
cout << item.first << endl;
}
}
work as intended? output is:
1
2
2
5
6
How std::sort
gets how to sort my int-string
pairs? How to make it do so for some class of mine as pair first
? Is there a way to sort by second
using std::sort
?