用std::set来保存char*/const char*

我们如何能在c++中使用set来保存char*/const char*呢?
答案是提供定制的template argument -> Compare.

#include <set>
#include <functional>

struct strless : public std::binary_function<const char*, const char*, bool>
{
    bool operator()(const char* s1, const char* s2) const
    {
        return strcmp(s1, s2) < 0;
    }
};

用法如下:
std::set<const char*, strless> myset;

然后你就可以正常使用了。
posted on 2006-04-12 18:07  万俊峰Kevin  阅读(1890)  评论(0编辑  收藏  举报