2016-01-13 100 views
1

我可以使用下面的代碼在Visual Studio 2013中編譯得到我係統的語言環境名稱。如果我在VS2015中編譯這個相同的代碼,我什麼都沒有回來!這是一個錯誤?那麼如何使用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; 
} 

回答

0

在VS2015他們作出如此的名稱,如果語言環境總是等於傳遞給構造函數(如果它是有效的)的說法:我認爲你必須使用setlocale()代替

// c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\xlocinfo 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 
        } 

std::cout << setlocale(LC_ALL, "") << endl; 

有它在std::locale你可以做

std::locale loc(setlocale(LC_ALL, "")); 

這適用於VS2013和VS2015。

+0

是的,工作。但是,如何在std :: locale變量中捕獲它? – Flethuseo

+0

@Flethuseo查看更新 –

相關問題