[英]C++ Get country code
I'm trying to get the country code (example: "UK" or "SI" or "GER") via GetGeoInfo(). 我正在尝试通过GetGeoInfo()获取国家代码(例如:“ UK”或“ SI”或“ GER”)。
GEOID GetUserGeoID(GEOCLASS_NATION);
Currently getting the value 16 from the above function ^ but looking in the table there's no number 16. 当前从上述函数^获得值16,但在表中没有数字16。
https://msdn.microsoft.com/en-us/library/windows/desktop/dd374073(v=vs.85).aspx https://msdn.microsoft.com/en-us/library/windows/desktop/dd374073(v=vs.85).aspx
I know it's only 3-4 lines of code but I can't seem to figure it out on my own. 我知道这只是3-4行代码,但我似乎无法自己弄清楚。 Any help would be appriciated. 任何帮助将被申请。
EDIT: 编辑:
GEOID myGEO = GetUserGeoID(GEOCLASS_NATION);
int sizeOfBuffer = GetGeoInfo(myGEO, GEO_ISO2, NULL, 0, 0);
WCHAR *buffer = new WCHAR[sizeOfBuffer];
int result = GetGeoInfo(myGEO, GEO_ISO2, buffer, sizeOfBuffer, 0);
Got it to display my country number but I don't know how I'd transform it into an ISO code. 得到它来显示我的国家/地区号码,但我不知道如何将其转换为ISO代码。
To get the country ISO: 要获得国家ISO:
GEOID myGEO = GetUserGeoID(GEOCLASS_NATION);
int sizeOfBuffer = GetGeoInfo(myGEO, GEO_ISO2, NULL, 0, 0);
WCHAR *buffer = new WCHAR[sizeOfBuffer];
int result = GetGeoInfo(myGEO, GEO_ISO2, buffer, sizeOfBuffer, 0);
wcout<<buffer;
Thanks to @Christophe and @Thomas. 感谢@Christophe和@Thomas。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.