stl set 仿函数 字符串从大到小排列

#include <iostream>
#include
<string.h>
#include
<stdlib.h>
#include
<algorithm>
#include
<set>
#include
<stdio.h>

using namespace std;

struct compare
{
bool operator ( ) (string s1, string s2)
{
return s1 > s2;
}
};

int main( )
{
set<string,compare>T;
int i;
char str[10];
//字符串插入
for(i = 0; i < 4; i++) {
scanf(
"%s",str);
T.insert(str);
}
//判断插入是否成功,已存在则返回0,插入成功将返回1
if (T.insert("tangcong").second)
cout
<<"set insert success"<<endl;
else
cout
<<"set insert fail!"<<endl;
for(set<string,compare>::iterator p = T.begin( ); p != T.end( ); p++)
cout
<<*p<<endl;
return 0;
}

posted on 2011-07-29 09:19  more think, more gains  阅读(1351)  评论(0编辑  收藏  举报

导航