对字符串进行排序,学会使用仿函数
时间:2015-05-19 10:36:38
收藏:0
阅读:109
#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)