setlocale(LC_ALL, ".65001");失败

南城边 2014-03-15 05:08:15
在CPP文件中我用EnumSystemCodePages(&EnumCodePagesProc,CP_SUPPORTED);函数运行查看了电脑支持的代码页中有65001,但是为什么setlocale(LC_ALL, ".65001");函数的返回值为NULL?后面输出UNICODE字符串TCHAR str[] = { TEXT( "一\u2701二\u2EC1三\u2ED3" ) };在黑框框上也显示为空?
...全文
675 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2014-03-17
  • 打赏
  • 举报
回复
setlocale, _wsetlocale Define the locale. char *setlocale( int category, const char *locale ); wchar_t *_wsetlocale( int category, const wchar_t *locale ); Routine Required Header Compatibility setlocale <locale.h> ANSI, Win 95, Win NT _wsetlocale <locale.h> or <wchar.h> Win 95, Win NT For additional compatibility information, see Compatibility in the Introduction. Libraries LIBC.LIB Single thread static library, retail version LIBCMT.LIB Multithread static library, retail version MSVCRT.LIB Import library for MSVCRT.DLL, retail version Return Value If a valid locale and category are given, the function returns a pointer to the string associated with the specified locale and category. If the locale or category is invalid, the function returns a null pointer and the current locale settings of the program are not changed. For example, the call setlocale( LC_ALL, "English" ); sets all categories, returning only the string English_USA.1252. If all categories are not explicitly set by a call to setlocale, the function returns a string indicating the current setting of each of the categories, separated by semicolons. If the locale argument is a null pointer, setlocale returns a pointer to the string associated with the category of the program’s locale; the program’s current locale setting is not changed. The null pointer is a special directive that tells setlocale to query rather than set the international environment. For example, the sequence of calls // Set all categories and return "English_USA.1252" setlocale( LC_ALL, "English" ); // Set only the LC_MONETARY category and return "French_France.1252" setlocale( LC_MONETARY, "French" ); setlocale( LC_ALL, NULL ); returns LC_COLLATE=English_USA.1252; LC_CTYPE=English_USA.1252; LC_MONETARY=French_France.1252; LC_NUMERIC=English_USA.1252; LC_TIME=English_USA.1252 which is the string associated with the LC_ALL category. You can use the string pointer returned by setlocale in subsequent calls to restore that part of the program’s locale information, assuming that your program does not alter the pointer or the string. Later calls to setlocale overwrite the string; you can use _strdup to save a specific locale string. Parameters category Category affected by locale locale Locale name Remarks Use the setlocale function to set, change, or query some or all of the current program locale information specified by locale and category. “Locale” refers to the locality (country and language) for which you can customize certain aspects of your program. Some locale-dependent categories include the formatting of dates and the display format for monetary values. _wsetlocale is a wide-character version of setlocale; the locale argument and return value of _wsetlocale are wide-character strings. _wsetlocale and setlocale behave identically otherwise. Generic-Text Routine Mappings TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined _tsetlocale setlocale setlocale _wsetlocale The category argument specifies the parts of a program’s locale information that are affected. The macros used for category and the parts of the program they affect are as follows: LC_ALL All categories, as listed below LC_COLLATE The strcoll, _stricoll, wcscoll, _wcsicoll, and strxfrm functions LC_CTYPE The character-handling functions (except isdigit, isxdigit, mbstowcs, and mbtowc, which are unaffected) LC_MONETARY Monetary-formatting information returned by the localeconv function LC_NUMERIC Decimal-point character for the formatted output routines (such as printf), for the data-conversion routines, and for the nonmonetary-formatting information returned by localeconv LC_TIME The strftime and wcsftime functions The locale argument is a pointer to a string that specifies the name of the locale. If locale points to an empty string, the locale is the implementation-defined native environment. A value of “C” specifies the minimal ANSI conforming environment for C translation. The “C” locale assumes that all char data types are 1 byte and that their value is always less than 256. The “C” locale is the only locale supported in Microsoft Visual C++ version 1.0 and earlier versions of Microsoft C/C++. Microsoft Visual C++ supports all the locales listed in Appendix A, Language and Country Strings. At program startup, the equivalent of the following statement is executed: setlocale( LC_ALL, "C" ); The locale argument takes the following form: locale :: "lang[_country[.code_page]]" | ".code_page" | "" | NULL The set of available languages, countries, and code pages includes all those supported by the Win32 NLS API. The set of language and country codes supported by setlocale is listed in Appendix A, Language and Country Strings. If locale is a null pointer, setlocale queries, rather than sets, the international environment, and returns a pointer to the string associated with the specified category. The program’s current locale setting is not changed. For example, setlocale( LC_ALL, NULL ); returns the string associated with category. The following examples pertain to the LC_ALL category. Either of the strings ".OCP" and ".ACP" can be used in place of a code page number to specify use of the system default OEM code page and system-default ANSI code page, respectively. setlocale( LC_ALL, "" ); Sets the locale to the default, which is the system-default ANSI code page obtained from the operating system. setlocale( LC_ALL, ".OCP" ); Explicitly sets the locale to the current OEM code page obtained from the operating system. setlocale( LC_ALL, ".ACP" ); Sets the locale to the ANSI code page obtained from the operating system. setlocale( LC_ALL, "[lang_ctry]" ); Sets the locale to the language and country indicated, using the default code page obtained from the host operating system. setlocale( LC_ALL, "[lang_ctry.cp]" ); Sets the locale to the language, country, and code page indicated in the [lang_ctry.cp] string. You can use various combinations of language, country, and code page. For example: setlocale( LC_ALL, "French_Canada.1252" ); // Set code page to French Canada ANSI default setlocale( LC_ALL, "French_Canada.ACP" ); // Set code page to French Canada OEM default setlocale( LC_ALL, "French_Canada.OCP" ); setlocale( LC_ALL, "[lang]" ); Sets the locale to the country indicated, using the default country for the language specified, and the system-default ANSI code page for that country as obtained from the host operating system. For example, the following two calls to setlocale are functionally equivalent: setlocale( LC_ALL, "English" ); setlocale( LC_ALL, "English_United States.1252" ); setlocale( LC_ALL, "[.code_page]" ); Sets the code page to the value indicated, using the default country and language (as defined by the host operating system) for the specified code page. The category must be either LC_ALL or LC_CTYPE to effect a change of code page. For example, if the default country and language of the host operating system are “United States” and “English,” the following two calls to setlocale are functionally equivalent: setlocale( LC_ALL, ".1252" ); setlocale( LC_ALL, "English_United States.1252"); For more information see the setlocale pragma in Preprocessor Reference. Example /* LOCALE.C: Sets the current locale to "Germany" using the * setlocale function and demonstrates its effect on the strftime * function. */ #include <stdio.h> #include <locale.h> #include <time.h> void main(void) { time_t ltime; struct tm *thetime; unsigned char str[100]; setlocale(LC_ALL, "German"); time (<ime); thetime = gmtime(<ime); /* %#x is the long date representation, appropriate to * the current locale */ if (!strftime((char *)str, 100, "%#x", (const struct tm *)thetime)) printf("strftime failed!\n"); else printf("In German locale, strftime returns '%s'\n", str); /* Set the locale back to the default environment */ setlocale(LC_ALL, "C"); time (<ime); thetime = gmtime(<ime); if (!strftime((char *)str, 100, "%#x", (const struct tm *)thetime)) printf("strftime failed!\n"); else printf("In 'C' locale, strftime returns '%s'\n", str); } Output In German locale, strftime returns 'Donnerstag, 22. April 1993' In 'C' locale, strftime returns 'Thursday, April 22, 1993' Locale Routines See Also localeconv, mblen, _mbstrlen, mbstowcs, mbtowc, strcoll Functions, strftime, strxfrm, wcstombs, wctomb
赵4老师 2014-03-17
  • 打赏
  • 举报
回复
SetLocaleInfo The SetLocaleInfo function sets an item of locale information. It does so by making an entry in the process portion of the locale table. This setting only affects the user override portion of the locale settings; it does not set the system defaults. Only certain types of locale information, or LCTYPE values, can be set by this function. See the following Remarks section for a list of valid LCTYPE values. The locale information is always passed in as a null-terminated Unicode string in the Unicode (W) version of the function, and as a null-terminated ANSI string in the ANSI (A) version. No integers are allowed by this function; any numeric values must be specified as Unicode or ANSI text. Each LCTYPE has a particular format, as noted in Locale Identifiers. BOOL SetLocaleInfo( LCID Locale, // locale identifier LCTYPE LCType, // type of information to set LPCTSTR lpLCData // pointer to information to set ); Parameters Locale Specifies the locale whose information the function will set. The locale provides a context for the string mapping or sort key generation. An application can use the MAKELCID macro to create a locale identifier. LCType Specifies the type of locale information to be set by the function. Note that only one LCTYPE may be specified per call. Not all LCTYPE values are valid; see the list of valid LCTYPE values in the following Remarks section. lpLCData Points to a null-terminated string containing the locale information the function will set. This should be an LPWSTR for the Unicode (W) version of the function, and an LPSTR for the ANSI (A) version. The information must be in the specified LCTYPE's particular format. Return Values If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, call GetLastError. GetLastError may return one of the following error codes: ERROR_INVALID_ACCESS ERROR_INVALID_FLAGS ERROR_INVALID_PARAMETER Remarks The following LCTYPE values are valid for this function: LOCALE_ICALENDARTYPE LOCALE_SDATE LOCALE_ICURRDIGITS LOCALE_SDECIMAL LOCALE_ICURRENCY LOCALE_SGROUPING LOCALE_IDIGITS LOCALE_SLIST LOCALE_IFIRSTDAYOFWEEK LOCALE_SLONGDATE LOCALE_IFIRSTWEEKOFYEAR LOCALE_SMONDECIMALSEP LOCALE_ILZERO LOCALE_SMONGROUPING LOCALE_IMEASURE LOCALE_SMONTHOUSANDSEP LOCALE_INEGCURR LOCALE_SNEGATIVESIGN LOCALE_INEGNUMBER LOCALE_SPOSITIVESIGN LOCALE_IPAPERSIZE LOCALE_SSHORTDATE LOCALE_ITIME LOCALE_STHOUSAND LOCALE_S1159 LOCALE_STIME LOCALE_S2359 LOCALE_STIMEFORMAT LOCALE_SCURRENCY LOCALE_SYEARMONTH Windows CE: Windows CE supports an additional LCTYPE value, LOCALE_SYEARMONTH. Windows CE does not support the LOCALE_IPAPERSIZE value. QuickInfo Windows NT: Requires version 3.5 or later. Windows: Requires Windows 95 or later. Windows CE: Requires version 1.0 or later. Header: Declared in winnls.h. Import Library: Use kernel32.lib. Unicode: Implemented as Unicode and ANSI versions on Windows NT. See Also National Language Support Overview, National Language Support Functions, GetLocaleInfo

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧