对字符串进行排序,学会使用仿函数

来源:互联网 发布:tgp优化启动速度 编辑:程序博客网 时间:2024/06/02 15:22
#include<iostream>#include<string>#include<algorithm>#include<cstdio>using namespace std;bool myCompare(char a, char b){    return a>b;}struct myCompare2{    bool operator()(char a, char b)    {        return a>b;    }};int main(){    string str("couragekshaojie");//    sort(str.begin(), str.end(), myCompare);    sort(str.begin(), str.end(), myCompare2());    printf("%s\n", str.c_str());    return 0;}

0 0
原创粉丝点击