这样做非常方便我们的开发,减少了代码量
[转载]http://www.cnblogs.com/boymgl/articles/1664340.html
1 bool strict_weak_ordering( const std::pair < int , std:: string > a, const std::pair < int , std:: string > b)
2 {
3 return a.first < b.first;
4 }
5
6 int main()
7 {
8 using namespace std;
9
10 vector < pair < int , string > > vec;
11
12 vec.push_back(make_pair < int , string > ( 5 , " hello " ));
13 vec.push_back(make_pair < int , string > ( 4 , " hell " ));
14 vec.push_back(make_pair < int , string > ( 6 , " hello, " ));
15
16 sort(vec.begin(), vec.end(), strict_weak_ordering);
17
18 vector < pair < int , string > > ::iterator it = vec.begin(), end = vec.end();
19
20 for (; it != end; ++ it)
21 cout << it -> second << endl;
22 return 0;
23 }