char *setlocale(
int category, // ロケールを適用するカテゴリ
const char *locale // ロケール指定子
);
wchar_t *_wsetlocale(
int category,
const wchar_t *locale
);
setlocale、_wsetlocale | MSDN
| 定数 | 設定対象の関数など |
|---|---|
| LC_ALL | 以下のすべて |
| LC_COLLATE | strcoll、_stricoll、wcscoll、_wcsicoll、strxfrm、_strncoll、_strnicoll、_wcsncoll、_wcsnicoll、wcsxfrm |
| LC_CTYPE | 文字列処理関数 (isdigit、isxdigit、mbstowcs、mbtowcを除く) |
| LC_MONETARY | localeconv関数の通貨形式 |
| LC_NUMERIC | printfなどの通貨形式以外の小数点文字、桁区切り記号。localeconfのグループ化コントロールの文字列 |
| LC_TIME | strftime、wcsftime |
localeは次項の形式で指定し、たとえばShift_JISに設定するには次のようにします。
setlocale( LC_ALL, ".932" );
環境の既定値に初期化するには、空の文字列を指定します。
setlocale( LC_ALL, "" );
現在の設定を取得するには、localeをNULLとします。
printf( "%s\n", setlocale( LC_ALL, NULL ) );
locale :: "locale_name"
| "language[_country_region[.code_page]]"
| ".code_page"
| "C"
| ""
| NULL
en-USbs-Cyrl-BAGreek_Greece.ACPEnglish_United States.1254 … 英語_米国.ANSIトルコ語 (非推奨の形式)Japanese_Japan.20932 … 日本語_日本.EUC-JP (非推奨の形式)1文字に2バイト以上を必要とするUTF-7 (65000) やUTF-8 (65001) には、コードページとして設定できません。つまり、setlocale(LC_ALL,".65001")のようには指定できません。Windows 10のバージョン1803以降ならば、setlocale(LC_ALL, ".UTF8")のように指定できます。UTF-8 のサポート - setlocale, _wsetlocale | Microsoft Learn
| 関数 | 説明 |
|---|---|
| GetTextCharset | Retrieves a character set identifier for the font that is currently selected into a specified device context. |
| GetTextCharsetInfo | Retrieves information about the character set of the font that is currently selected into a specified device context. |
| TranslateCharsetInfo | Translates character set information and sets all members of a destination structure to appropriate values. |
| IsDBCSLeadByte | Determines if a specified character is a lead byte for the system default Windows ANSI code page (CP_ACP). |
| IsDBCSLeadByteEx | Determines if a specified character is potentially a lead byte. |
| IsTextUnicode | Determines if a buffer is likely to contain a form of Unicode text. |
| MultiByteToWideChar | Maps a character string to a UTF-16 (wide character) string. |
| WideCharToMultiByte | Maps a UTF-16 (wide character) string to a new character string. |
| BytesToUnicode | Do not use. |
| UnicodeToBytes | Do not use. |
| NlsDllCodePageTranslation | Do not use. |
文字列 (LPCSTR) を、UTF-16文字列 (LPWSTR) へマップします。
int MultiByteToWideChar( _In_ UINT CodePage, // 変換に使用するコードページ _In_ DWORD dwFlags, // 変換タイプを指定するフラグ _In_ LPCSTR lpMultiByteStr, // 変換する文字列へのポインタ _In_ int cbMultiByte, // 変換する文字列のバイト数 _Out_opt_ LPWSTR lpWideCharStr, // 変換後の文字列を格納するバッファへのポインタ _In_ int cchWideChar // 変換後の文字列を格納するバッファの文字数 );MultiByteToWideChar function (Windows) | MSDN MultiByteToWideChar 関数 | MSDN
UTF-16文字列を、新しい文字列へマップします。
int WideCharToMultiByte( _In_ UINT CodePage, // 変換に使用するコードページ _In_ DWORD dwFlags, // 変換タイプを指定するフラグ _In_ LPCWSTR lpWideCharStr, // 変換するUnicode文字列へのポインタ _In_ int cchWideChar, // 変換するUnicode文字列の文字数 _Out_opt_ LPSTR lpMultiByteStr, // 変換後の文字列を格納するバッファへのポインタ _In_ int cbMultiByte, // 変換後の文字列を格納するバッファのバイト数 _In_opt_ LPCSTR lpDefaultChar, // 指定のコードページで変換できなかったときに使用する文字へのポインタ _Out_opt_ LPBOOL lpUsedDefaultChar // lpDefaultCharが使用されたときに設定されるフラグへのポインタ );WideCharToMultiByte function (Windows) | MSDN WideCharToMultiByte 関数 | MSDN