| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 677 人关注过本帖
标题:[讨论][求助]syntax to use stl sort() on char arrays
只看楼主 加入收藏
HJin
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:401
专家分:0
注 册:2007-6-9
收藏
 问题点数:0 回复次数:0 
[讨论][求助]syntax to use stl sort() on char arrays

#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;

struct cmp
{
//Return true if s1 < s2; otherwise, return false.
bool operator()(const char *s1, const char * s2)
{
return strcmp(s1, s2) < 0;
}
};


int main(int argc, char* argv[])
{
int i;

sort(argv, argv + argc, cmp());
for (i = 0; i < argc; ++i)
{
cout << argv[i] << endl;
}

char s[][6] = {"sun", "moon", "earth"};

/**
need help here: sort char arrays. I cannot get the syntax working.

Please suggest a way to call sort() as simple as possible, including writing a new
predictor for sort().
*/
// sort(s, s + 3);

for (i = 0; i < 3; ++i)
{
cout << s[i] << endl;
}


return 0;
}

[此贴子已经被作者于2007-9-22 1:56:00编辑过]

搜索更多相关主题的帖子: syntax stl sort arrays char 
2007-09-22 00:52
快速回复:[讨论][求助]syntax to use stl sort() on char arrays
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.038056 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved