打印所有的std ::区域名称(Windows) [英] Print all std::locale names (Windows)

查看:159
本文介绍了打印所有的std ::区域名称(Windows)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序检查德语单词大写字母。

My program checks for uppercase letters in German language.

#include <iostream>
#include <boost/algorithm/string/classification.hpp>
#include <boost/locale.hpp>

using namespace std;

int main()
{
    locale::global(locale("Germany_german"));
    //locale::global(locale("de_DE.UTF-8")); //Also tried "de_DE.UTF-8", but does not work

    string str1 = "über";
    cout << boolalpha << any_of(str1.begin(), str1.end(), boost::algorithm::is_upper()) << endl;

    string str2 = "Ää";
    cout << boolalpha << any_of(str2.begin(), str2.end(), boost::algorithm::is_upper()) << endl;

    return 0;
}

程序与控制台错误崩溃

program crashes with error on console

terminate called after throwing an instance of 'std::runtime_error'
  what():  locale::facet::_S_create_c_locale name not valid

我不知道,准确的语言环境的字符串是什么,de_DE.UTF-8不能正常工作。

I don't know what that exact locale string is, "de_DE.UTF-8" doesn't work as well.

有什么办法,我可以得到确切的区域名称字符串由操作系统支持的所有语言环境。可能有一个清单某处的头文件,但我没有看到任何&LT;现场方式&gt;

Is there any way I can get exact locale name strings for all locales supported by OS. May be there is a list somewhere in header files, but I don't see anything <locale> header.

推荐答案

我写了一个程序,打印所有支持的语言。

I wrote a program to print all supported locale names.

#include <Windows.h>

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <ostream>
#include <iterator>

using namespace std;

vector<wstring> locals;

BOOL CALLBACK MyFuncLocaleEx(LPWSTR pStr, DWORD dwFlags, LPARAM lparam)
{
    locals.push_back(pStr);
    return TRUE;
}

int _tmain(int argc, _TCHAR* argv[])
{
    EnumSystemLocalesEx(MyFuncLocaleEx, LOCALE_ALL, NULL, NULL);

    for (vector<wstring>::const_iterator str = locals.begin(); str != locals.end(); ++str)
        wcout << *str << endl;

    wcout << "Total " << locals.size() << " locals found." << endl;

    return 0;
}

的伟大工程。

...
de
de-AT
de-CH
de-DE
de-DE_phoneb
de-LI
de-LU
...    
Total 429 locals found.

这篇关于打印所有的std ::区域名称(Windows)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆