如何使用VS2015获取区域设置名称
How do I get the locale name using VS2015?
我可以使用下面在Visual Studio 2013中编译的代码来获取系统的区域设置名称。如果我在VS2015中编译同样的代码,我将一无所获!这是个虫子吗?那么,如何使用VS2015获得当前系统区域设置的名称?
#include "stdafx.h"
#include <iostream>
#include <locale>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
std::cout << std::locale("").name().c_str() << endl;
}
在VS2015中,如果区域设置,则名称始终等于传递给构造函数的参数(如果有效):
// c:Program Files (x86)Microsoft Visual Studio 14.0VCincludexlocinfo line 360
void _Construct(const string &_Str,
category _Cat)
{ // construct a locale with named facets
bool _Bad = false;
_Init();
if (_Cat != none)
{ // worth adding, do it
_TRY_BEGIN
_BEGIN_LOCINFO(_Lobj(_Cat, _Str.c_str()))
if (_Badname(_Lobj))
_Bad = true;
else
{ // name okay, build the locale
_Locimp::_Makeloc(_Lobj, _Cat, _Ptr, 0);
// The two lines below were added in VS2015
_Ptr->_Catmask = _Cat;
_Ptr->_Name = _Str.c_str(); // <--- Here they set the name forcefully
}
我认为您必须使用setlocale():
std::cout << setlocale(LC_ALL, "") << endl;
要在std::locale
中进行
std::locale loc(setlocale(LC_ALL, ""));
这适用于VS2013和VS2015。
相关文章:
- 在 Linux 中存储区域设置名称的缓冲区大小应该是多少?
- 提升区域设置规范化带状字符,但不规范化重音
- 是否有任何区域设置会影响宽字符编码?
- 提升获取文本的区域设置"Conversion failed"
- 提升 1.41.0 : 提升::区域设置替代方案?
- std::locale 向"en_US.UTF-8"区域设置抛出runtime_error异常
- 默认情况具有哪个区域设置
- 区域设置是否有定义负号的方面?
- QT 将文本翻译成特定的区域设置
- 我可以强制 QFileDialog 使用系统区域设置而不是系统语言吗?
- 如何调用 GetAltMonthNames 来填充外部区域设置月份字符串的安全数组
- 提升区域设置不完整类型boundary_indexing<char32_t>
- 默认区域设置"root"在 ICU 中如何工作?
- std::regex总是可以识别区域设置吗?
- std::string 的运算符<是否应该受到当前区域设置的影响?
- C++为任何区域设置区域设置
- 如何显示与系统不同的区域设置的QDate月
- Mac OS X 中的设置区域设置不起作用
- 在 OS X 上设置区域设置崩溃
- C++在整个程序中设置区域设置