是否可以创建自己的自定义区域设置

时间:2010-04-26 09:58:41

标签: c++ locale

由于Windows默认情况下没有支持UTF8的C ++语言环境,我想构建一个支持UTF8的自定义语言环境对象(通过使用自定义ctype facet创建它)。

如何构建具有我自己的ctype实现的语言环境对象(我只找到使用现有语言环境作为基础构建语言环境的函数。)

如果C ++根本不支持使用自定义ctype facet构建语言环境,为什么会这样呢?

1 个答案:

答案 0 :(得分:5)

可以通过继承std :: locale :: facet来创建自定义构面。语言环境可以使用这些自定义构面,如下面的代码所示:

class custom_facet : public std::locale::facet {
public:
    static std::locale::id id;
    custom_facet(int);  
    int custom_value() const; 
    };

std::locale  custom_locale ( std::locale(), new custom_facet() );
int s = std::use_facet<custom_facet>(custom_locale).custom_value();
相关问题