代码之家  ›  专栏  ›  技术社区  ›  Loki Astari

有效的区域设置名称

  •  22
  • Loki Astari  · 技术社区  · 16 年前

    如何找到有效的语言环境名称?


    但关于其他平台的信息也会很有用。

    #include <fstream>
    #include <iostream>
    
    
    int main(int argc,char* argv[])
    {
        try
        {
            std::wifstream  data;
            data.imbue(std::locale("en_US.UTF-16"));
            data.open("Plop");
        }
        catch(std::exception const& e)
        {
            std::cout << "Exception: " << e.what() << "\n";
            throw;
        }
    }
    
    % g++ main.cpp
    % ./a.out
    Exception: locale::facet::_S_create_c_locale name not valid
    Abort
    
    1 回复  |  直到 16 年前
        1
  •  23
  •   Community Mohan Dere    9 年前

    This page says:

    LANG LC_ALL (在POSIX系统上,您可以键入 locale -a 以列出受支持的区域设置的名称。)

    应该对你有用。

    This stack overflow question 可能也是相关的,但他似乎没有太多的回应。

    编辑

    要使用UTF-16,您可能需要使用 libiconv this question .

    推荐文章