关系仿函数-大于

#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

class Print
{
public:
   void operator()(int i)
   {
      cout << i << endl;
   }
};

int main()
{
   vector<int> v;
   v.push_back(1);
   v.push_back(5);
   v.push_back(3);   

   sort(v.begin(), v.end(), greater<int>());
   for_each(v.begin(), v.end(), Print());

   return 0;
}
$ ./a.out 
5
3
1
posted @ 2022-07-31 11:03  thomas_blog  阅读(16)  评论(0编辑  收藏  举报