2013-05-08 55 views
1

說,我可以用_create_locale這樣從我的C程序中設置的語言環境:如何獲取我的線程的語言環境名稱?

localeUS = _create_locale(LC_ALL, "English_United States.1252"); 

但我需要的是相反的,即檢索區域名稱(函數的第二個參數上面)調用線。任何想法如何做到這一點?

PS。我知道現代Windows使用LCID。爲了與舊代碼兼容,我需要此區域名稱。

回答

3

希望你可以使用標準C++。

std::locale::name

#include <locale> 
#include <iostream> 
#include <string> 

int main() 
{ 
    std::locale loc(std::locale(), new std::ctype<char>); 
    std::cout << "The default locale is " << std::locale().name() << '\n' 
       << "The user's locale is " << std::locale("").name() << '\n' 
       << "A nameless locale is " << loc.name() << '\n'; 
} 

輸出:

The default locale is C 
The user's locale is en_US.UTF8 
A nameless locale is * 
+1

感謝。剛剛通過逆向工程發現你的示例,簡單地做'strCurrentLocale = setlocale(LC_ALL,「」);'會做我需要的。 – c00000fd 2013-05-08 02:13:22

+0

根據鏈接文檔,'std :: locale()'*「構造**全局** C++語言環境」*「的副本。沒有記錄'std :: locale(「」)'的行爲。由於Windows控制每個線程的語言環境,因此檢索當前線程的語言環境的方法是什麼? – IInspectable 2017-08-01 01:57:04

相關問題