How to get current locale of my environment?

前端 未结 5 613
挽巷
挽巷 2020-12-28 13:06

Had tried following code in Linux, but always return \'C\' under different LANG settings.

#include 
#include 
#i         


        
5条回答
  •  太阳男子
    2020-12-28 13:45

    A good alternative to consider instead of std::locale is boost::locale which is capable of returning more reliable information - see http://www.boost.org/doc/libs/1_52_0/libs/locale/doc/html/locale_information.html

    boost::locale::info has the following member functions:

    std::string name() -- the full name of the locale, for example en_US.UTF-8
    std::string language() -- the ISO-639 language code of the current locale, for example "en".
    std::string country() -- the ISO-3199 country code of the current locale, for example "US".
    std::string variant() -- the variant of current locale, for example "euro".
    std::string encoding() -- the encoding used for char based strings, for example "UTF-8"
    bool utf8() -- a fast way to check whether the encoding is UTF-8.
    

提交回复
热议问题