名前空間
変種
操作

「cpp/locale/setlocale」の版間の差分

提供: cppreference.com
< cpp‎ | locale
(r2.7.3) (ロボットによる 追加: de, en, es, fr, it, pt, ru, zh)
(Use {{lc}}. Update links. Various fixes.)
2行: 2行:
 
{{cpp/title|setlocale}}
 
{{cpp/title|setlocale}}
 
{{cpp/locale/navbar}}
 
{{cpp/locale/navbar}}
{{ddcl list begin}}
+
{{begin}}
{{ddcl list header|clocale}}
+
{{header|clocale}}
{{ddcl list item |
+
{{|
 
char* setlocale( int category, const char* locale);
 
char* setlocale( int category, const char* locale);
 
}}
 
}}
{{ddcl list end}}
+
{{end}}
  
 
{{tr|{{tt|setlocale}}関数は、新しいCロケールとして指定されているシステムのロケールまたはその一部をインストールします。修正は引き続き有効であると{{tt|setlocale}}への次のコールまで、ロケールに依存するすべてのCライブラリ関数の実行に影響を与えます。 {{tt|locale}}がNULLポインターである場合、{{tt|setlocale}}は、それを変更することなく、現在のCロケールを照会.|The {{tt|setlocale}} function installs the specified system locale or its portion as the new C locale. The modifications remain in effect and influences the execution of all locale-sensitive C library functions until the next call to {{tt|setlocale}}. If {{tt|locale}} is a null pointer, {{tt|setlocale}} queries the current C locale without modifying it.}}
 
{{tr|{{tt|setlocale}}関数は、新しいCロケールとして指定されているシステムのロケールまたはその一部をインストールします。修正は引き続き有効であると{{tt|setlocale}}への次のコールまで、ロケールに依存するすべてのCライブラリ関数の実行に影響を与えます。 {{tt|locale}}がNULLポインターである場合、{{tt|setlocale}}は、それを変更することなく、現在のCロケールを照会.|The {{tt|setlocale}} function installs the specified system locale or its portion as the new C locale. The modifications remain in effect and influences the execution of all locale-sensitive C library functions until the next call to {{tt|setlocale}}. If {{tt|locale}} is a null pointer, {{tt|setlocale}} queries the current C locale without modifying it.}}
  
 
===パラメータ===
 
===パラメータ===
{{param list begin}}
+
{{begin}}
{{param list item | category |{{tr| ロケールカテゴリ識別子、{{rlp|LC_categories|{{tr|LC_xxx|LC_xxx}}}}マクロの一つ。 nullの可能性があります.| locale category identifier, one of the {{rlp|LC_categories|{{tr|LC_xxx|LC_xxx}}}} macros. May be null.}}}}
+
{{| category |{{tr| ロケールカテゴリ識別子、{{rlp|LC_categories|{{tr|LC_xxx|LC_xxx}}}}マクロの一つ。 nullの可能性があります.| locale category identifier, one of the {{rlp|LC_categories|{{tr|LC_xxx|LC_xxx}}}} macros. May be null.}}}}
{{param list item | locale |{{tr| システム固有のロケール識別子。最小限のロケール用のユーザの優先ロケールまたは{{c|""}}ため{{c|"C"}}することができます | system-specific locale identifier. Can be {{c|""}} for the user-preferred locale or {{c|"C"}} for the minimal locale }}}}
+
{{| locale |{{tr| システム固有のロケール識別子。最小限のロケール用のユーザの優先ロケールまたは{{c|""}}ため{{c|"C"}}することができます | system-specific locale identifier. Can be {{c|""}} for the user-preferred locale or {{c|"C"}} for the minimal locale }}}}
{{param list end}}
+
{{end}}
  
 
===値を返します===
 
===値を返します===
25行: 25行:
 
{{tr|戻り値の型が{{c|char*}}ですが、ポイント先の文字を変更すると、未定義の動作です.|Although the return type is {{c|char*}}, modifying the pointed-to characters is undefined behavior.}}
 
{{tr|戻り値の型が{{c|char*}}ですが、ポイント先の文字を変更すると、未定義の動作です.|Although the return type is {{c|char*}}, modifying the pointed-to characters is undefined behavior.}}
  
{{tr|{{tt|setlocale}}はロケールに依存した機能の実行に影響を与えるグローバルな状態を変更するので、別のスレッドが次のいずれかの機能を実行している間、それは、一つのスレッドからそれを呼び出すように未定義の動作です:{{c|std::fprintf}}、{{c|std::isprint}}、{{c|std::iswdigit}}、{{c|std::localeconv}}、{{c|std::tolower}}、{{c|std::fscanf}}、{{c|std::ispunct}}、 {{c|std::iswgraph}}、{{c|std::mblen}}、{{c|std::toupper}}、{{c|std::isalnum}}、{{c|std::isspace}}、{{c|std::iswlower}}、{{c|std::mbstowcs}}、{{c|std::towlower}}、{{c|std::isalpha}}、{{c|std::isupper}}、{{c|std::iswprint}}、{{c|std::mbtowc}}、{{c|std::towupper}}、{{c|std::isblank}}、{{c|std::iswalnum}}、{{c|std::iswpunct}}、{{c|std::setlocale}}、{{c|std::wcscoll}}、{{c|std::iscntrl}}、{{c|std::iswalpha}}、{{c|std::iswspace}}、{{c|std::strcoll}}、{{c|std::wcstod}}、{{c|std::isdigit}}、{{c|std::iswblank}}、 {{c|std::iswupper}}、{{c|std::strerror}}、{{c|std::wcstombs}}、{{c|std::isgraph}}、{{c|std::iswcntrl}}、{{c|std::iswxdigit}}、{{c|std::strtod}}、{{c|std::wcsxfrm}}、{{c|std::islower}}、{{c|std::iswctype}}、{{c|std::isxdigit}}.|Because {{tt|setlocale}} modifies global state which affects execution of locale-dependent functions, it is undefined behavior to call it from one thread, while another thread is executing any of the following functions: {{c|std::fprintf}}, {{c|std::isprint}}, {{c|std::iswdigit}}, {{c|std::localeconv}}, {{c|std::tolower}}, {{c|std::fscanf}}, {{c|std::ispunct}}, {{c|std::iswgraph}}, {{c|std::mblen}}, {{c|std::toupper}}, {{c|std::isalnum}}, {{c|std::isspace}}, {{c|std::iswlower}}, {{c|std::mbstowcs}}, {{c|std::towlower}}, {{c|std::isalpha}}, {{c|std::isupper}}, {{c|std::iswprint}}, {{c|std::mbtowc}}, {{c|std::towupper}}, {{c|std::isblank}}, {{c|std::iswalnum}}, {{c|std::iswpunct}}, {{c|std::setlocale}}, {{c|std::wcscoll}}, {{c|std::iscntrl}}, {{c|std::iswalpha}}, {{c|std::iswspace}}, {{c|std::strcoll}}, {{c|std::wcstod}}, {{c|std::isdigit}}, {{c|std::iswblank}}, {{c|std::iswupper}}, {{c|std::strerror}}, {{c|std::wcstombs}}, {{c|std::isgraph}}, {{c|std::iswcntrl}}, {{c|std::iswxdigit}}, {{c|std::strtod}}, {{c|std::wcsxfrm}}, {{c|std::islower}}, {{c|std::iswctype}}, {{c|std::isxdigit}}.}}
+
{{tr|{{tt|setlocale}}はロケールに依存した機能の実行に影響を与えるグローバルな状態を変更するので、別のスレッドが次のいずれかの機能を実行している間、それは、一つのスレッドからそれを呼び出すように未定義の動作です:{{|std::fprintf}}、{{|std::isprint}}、{{|std::iswdigit}}、{{|std::localeconv}}、{{|std::tolower}}、{{|std::fscanf}}、{{|std::ispunct}}、 {{|std::iswgraph}}、{{|std::mblen}}、{{|std::toupper}}、{{|std::isalnum}}、{{|std::isspace}}、{{|std::iswlower}}、{{|std::mbstowcs}}、{{|std::towlower}}、{{|std::isalpha}}、{{|std::isupper}}、{{|std::iswprint}}、{{|std::mbtowc}}、{{|std::towupper}}、{{|std::isblank}}、{{|std::iswalnum}}、{{|std::iswpunct}}、{{|std::setlocale}}、{{|std::wcscoll}}、{{|std::iscntrl}}、{{|std::iswalpha}}、{{|std::iswspace}}、{{|std::strcoll}}、{{|std::wcstod}}、{{|std::isdigit}}、{{|std::iswblank}}、 {{|std::iswupper}}、{{|std::strerror}}、{{|std::wcstombs}}、{{|std::isgraph}}、{{|std::iswcntrl}}、{{|std::iswxdigit}}、{{|std::strtod}}、{{|std::wcsxfrm}}、{{|std::islower}}、{{|std::iswctype}}、{{|std::isxdigit}}.|Because {{tt|setlocale}} modifies global state which affects execution of locale-dependent functions, it is undefined behavior to call it from one thread, while another thread is executing any of the following functions: {{|std::fprintf}}, {{|std::isprint}}, {{|std::iswdigit}}, {{|std::localeconv}}, {{|std::tolower}}, {{|std::fscanf}}, {{|std::ispunct}}, {{|std::iswgraph}}, {{|std::mblen}}, {{|std::toupper}}, {{|std::isalnum}}, {{|std::isspace}}, {{|std::iswlower}}, {{|std::mbstowcs}}, {{|std::towlower}}, {{|std::isalpha}}, {{|std::isupper}}, {{|std::iswprint}}, {{|std::mbtowc}}, {{|std::towupper}}, {{|std::isblank}}, {{|std::iswalnum}}, {{|std::iswpunct}}, {{|std::setlocale}}, {{|std::wcscoll}}, {{|std::iscntrl}}, {{|std::iswalpha}}, {{|std::iswspace}}, {{|std::strcoll}}, {{|std::wcstod}}, {{|std::isdigit}}, {{|std::iswblank}}, {{|std::iswupper}}, {{|std::strerror}}, {{|std::wcstombs}}, {{|std::isgraph}}, {{|std::iswcntrl}}, {{|std::iswxdigit}}, {{|std::strtod}}, {{|std::wcsxfrm}}, {{|std::islower}}, {{|std::iswctype}}, {{|std::isxdigit}}.}}
  
 
===例===
 
===例===
56行: 56行:
  
 
===も参照してください===
 
===も参照してください===
{{dcl list begin}}
+
{{begin}}
{{dcl list template | cpp/locale/dcl list LC_categories}}
+
{{| cpp/locale/LC_categories}}
{{dcl list template | cpp/locale/dcl list locale}}
+
{{| cpp/locale/locale}}
{{dcl list see c | c/locale/setlocale}}
+
{{see c | c/locale/setlocale}}
{{dcl list end}}
+
{{end}}
  
 
[[de:cpp/locale/setlocale]]
 
[[de:cpp/locale/setlocale]]

2013年7月2日 (火) 14:09時点における版

 
 
 
ヘッダ <clocale> で定義
char* setlocale( int category, const char* locale);
setlocale関数は、新しいCロケールとして指定されているシステムのロケールまたはその一部をインストールします。修正は引き続き有効であるとsetlocaleへの次のコールまで、ロケールに依存するすべてのCライブラリ関数の実行に影響を与えます。 localeがNULLポインターである場合、setlocaleは、それを変更することなく、現在のCロケールを照会.
Original:
The setlocale function installs the specified system locale or its portion as the new C locale. The modifications remain in effect and influences the execution of all locale-sensitive C library functions until the next call to setlocale. If locale is a null pointer, setlocale queries the current C locale without modifying it.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

目次

パラメータ

category - マクロの一つ。 nullの可能性があります.
Original:
locale -
システム固有のロケール識別子。最小限のロケール用のユーザの優先ロケールまたは""ため"C"することができます
Original:
system-specific locale identifier. Can be "" for the user-preferred locale or "C" for the minimal locale
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

値を返します

変更を適用した後のCロケールを識別狭いNULLで終わる文字列があれば、失敗した場合はNULLポインタへのポインタ..
Original:
Pointer to a narrow null-terminated string identifying the C locale after applying the changes, if any, or null pointer on failure.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

ノート

任意のユーザコードが実行される前に、プログラムの起動時に、std::setlocale(LC_ALL, "C");のと同じ処理が実行され.
Original:
During program startup, the equivalent of std::setlocale(LC_ALL, "C"); is executed before any user code is run.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
戻り値の型がchar*ですが、ポイント先の文字を変更すると、未定義の動作です.
Original:
Although the return type is char*, modifying the pointed-to characters is undefined behavior.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
setlocaleはロケールに依存した機能の実行に影響を与えるグローバルな状態を変更するので、別のスレッドが次のいずれかの機能を実行している間、それは、一つのスレッドからそれを呼び出すように未定義の動作です:std::fprintfstd::isprintstd::iswdigitstd::localeconvstd::tolowerstd::fscanfstd::ispunctstd::iswgraphstd::mblenstd::toupperstd::isalnumstd::isspacestd::iswlowerstd::mbstowcsstd::towlowerstd::isalphastd::isupperstd::iswprintstd::mbtowcstd::towupperstd::isblankstd::iswalnumstd::iswpunctstd::setlocalestd::wcscollstd::iscntrlstd::iswalphastd::iswspacestd::strcollstd::wcstodstd::isdigitstd::iswblankstd::iswupperstd::strerrorstd::wcstombsstd::isgraphstd::iswcntrlstd::iswxdigitstd::strtodstd::wcsxfrmstd::islowerstd::iswctypestd::isxdigit.
Original:
Because setlocale modifies global state which affects execution of locale-dependent functions, it is undefined behavior to call it from one thread, while another thread is executing any of the following functions: std::fprintf, std::isprint, std::iswdigit, std::localeconv, std::tolower, std::fscanf, std::ispunct, std::iswgraph, std::mblen, std::toupper, std::isalnum, std::isspace, std::iswlower, std::mbstowcs, std::towlower, std::isalpha, std::isupper, std::iswprint, std::mbtowc, std::towupper, std::isblank, std::iswalnum, std::iswpunct, std::setlocale, std::wcscoll, std::iscntrl, std::iswalpha, std::iswspace, std::strcoll, std::wcstod, std::isdigit, std::iswblank, std::iswupper, std::strerror, std::wcstombs, std::isgraph, std::iswcntrl, std::iswxdigit, std::strtod, std::wcsxfrm, std::islower, std::iswctype, std::isxdigit.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

#include <cstdio>
#include <clocale>
#include <ctime>
#include <cwchar>
 
int main()
{
    // the C locale will be UTF-8 enabled English;
    // decimal dot will be German
    // date and time formatting will be Japanese
    std::setlocale(LC_ALL, "en_US.UTF-8");
    std::setlocale(LC_NUMERIC, "de_DE");
    std::setlocale(LC_TIME, "ja_JP");
 
    wchar_t str[100];
    std::time_t t = std::time(NULL);
    std::wcsftime(str, 100, L"%A %c", std::localtime(&t));
    std::wprintf(L"Number: %.2f\nDate: %Ls\n", 3.14, str);
}

出力:

Number: 3,14
Date: 月曜日 2011年12月19日 18時04分40秒

も参照してください

std::setlocale のためのロケールカテゴリ
(マクロ定数) [edit]
文化の違いをカプセル化する多相的なファセットの集合
(クラス) [edit]