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

180it 2020-10-09 PM 2891℃ 0条

include

include <string.h>

include <stdlib.h>

include

include

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;

}

支付宝打赏支付宝打赏 微信打赏微信打赏

如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!

标签: none

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