名前空間
変種
操作

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

提供: cppreference.com
< cpp‎ | locale
(Fix some translations)
 
1行: 1行:
{{tr_note}}
 
 
{{cpp/title|setlocale}}
 
{{cpp/title|setlocale}}
 
{{cpp/locale/navbar}}
 
{{cpp/locale/navbar}}
9行: 8行:
 
{{dcl end}}
 
{{dcl 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.}}
+
{{tt|setlocale}} {{tt|setlocale}} C {{tt|locale}} {{tt|setlocale}} C
  
===パラメータ===
+
======
 
{{par begin}}
 
{{par begin}}
{{par | 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.}}}}
+
{{par | category | ロケールカテゴリ識別子、 {{rlp|LC_categories|LC_xxx}} }}
{{par | locale |{{tr| システム固有のロケール識別子。最小限のロケール用のユーザの優先ロケールまたは{{c|""}}ため{{c|"C"}}することができます | system-specific locale identifier. Can be {{c|""}} for the user-preferred locale or {{c|"C"}} for the minimal locale }}}}
+
{{par | locale | {{c|""}}{{c|"C"}} }}
 
{{par end}}
 
{{par end}}
  
===値を返します===
+
======
{{tr|変更を適用した後のCロケールを識別狭いNULLで終わる文字列があれば、失敗した場合はNULLポインタへのポインタ..|Pointer to a narrow null-terminated string identifying the C locale after applying the changes, if any, or null pointer on failure.}}
+
 +
 
 +
{{|}}
  
 
===ノート===
 
===ノート===
{{tr|任意のユーザコードが実行される前に、プログラムの起動時に、{{c|std::setlocale(LC_ALL, "C");}}のと同じ処理が実行され.|During program startup, the equivalent of {{c|std::setlocale(LC_ALL, "C");}} is executed before any user code is run.}}
+
{{c|std::setlocale(LC_ALL, "C");}}
 +
 
 +
|
 +
 
 +
, {{|std::setlocale, }}}}
  
{{tr|戻り値の型が{{c|char*}}ですが、ポイント先の文字を変更すると、未定義の動作です.|Although the return type is {{c|char*}}, modifying the pointed-to characters is undefined behavior.}}
+
  
{{tr|{{tt|setlocale}}はロケールに依存した機能の実行に影響を与えるグローバルな状態を変更するので、別のスレッドが次のいずれかの機能を実行している間、それは、一つのスレッドからそれを呼び出すように未定義の動作です:{{lc|std::fprintf}}、{{lc|std::isprint}}、{{lc|std::iswdigit}}、{{lc|std::localeconv}}、{{lc|std::tolower}}、{{lc|std::fscanf}}、{{lc|std::ispunct}}、 {{lc|std::iswgraph}}、{{lc|std::mblen}}、{{lc|std::toupper}}、{{lc|std::isalnum}}、{{lc|std::isspace}}、{{lc|std::iswlower}}、{{lc|std::mbstowcs}}、{{lc|std::towlower}}、{{lc|std::isalpha}}、{{lc|std::isupper}}、{{lc|std::iswprint}}、{{lc|std::mbtowc}}、{{lc|std::towupper}}、{{lc|std::isblank}}、{{lc|std::iswalnum}}、{{lc|std::iswpunct}}、{{lc|std::setlocale}}、{{lc|std::wcscoll}}、{{lc|std::iscntrl}}、{{lc|std::iswalpha}}、{{lc|std::iswspace}}、{{lc|std::strcoll}}、{{lc|std::wcstod}}、{{lc|std::isdigit}}、{{lc|std::iswblank}}、 {{lc|std::iswupper}}、{{lc|std::strerror}}、{{lc|std::wcstombs}}、{{lc|std::isgraph}}、{{lc|std::iswcntrl}}、{{lc|std::iswxdigit}}、{{lc|std::strtod}}、{{lc|std::wcsxfrm}}、{{lc|std::islower}}、{{lc|std::iswctype}}、{{lc|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: {{lc|std::fprintf}}, {{lc|std::isprint}}, {{lc|std::iswdigit}}, {{lc|std::localeconv}}, {{lc|std::tolower}}, {{lc|std::fscanf}}, {{lc|std::ispunct}}, {{lc|std::iswgraph}}, {{lc|std::mblen}}, {{lc|std::toupper}}, {{lc|std::isalnum}}, {{lc|std::isspace}}, {{lc|std::iswlower}}, {{lc|std::mbstowcs}}, {{lc|std::towlower}}, {{lc|std::isalpha}}, {{lc|std::isupper}}, {{lc|std::iswprint}}, {{lc|std::mbtowc}}, {{lc|std::towupper}}, {{lc|std::isblank}}, {{lc|std::iswalnum}}, {{lc|std::iswpunct}}, {{lc|std::setlocale}}, {{lc|std::wcscoll}}, {{lc|std::iscntrl}}, {{lc|std::iswalpha}}, {{lc|std::iswspace}}, {{lc|std::strcoll}}, {{lc|std::wcstod}}, {{lc|std::isdigit}}, {{lc|std::iswblank}}, {{lc|std::iswupper}}, {{lc|std::strerror}}, {{lc|std::wcstombs}}, {{lc|std::isgraph}}, {{lc|std::iswcntrl}}, {{lc|std::iswxdigit}}, {{lc|std::strtod}}, {{lc|std::wcsxfrm}}, {{lc|std::islower}}, {{lc|std::iswctype}}, {{lc|std::isxdigit}}.}}
+
setlocale
  
 
===例===
 
===例===
42行: 47行:
 
     // date and time formatting will be Japanese
 
     // date and time formatting will be Japanese
 
     std::setlocale(LC_ALL, "en_US.UTF-8");
 
     std::setlocale(LC_ALL, "en_US.UTF-8");
     std::setlocale(LC_NUMERIC, "de_DE");
+
     std::setlocale(LC_NUMERIC, "de_DE");
     std::setlocale(LC_TIME, "ja_JP");
+
     std::setlocale(LC_TIME, "ja_JP");
  
 
     wchar_t str[100];
 
     wchar_t str[100];
55行: 60行:
 
}}
 
}}
  
===参照===
+
======
 
{{dsc begin}}
 
{{dsc begin}}
 
{{dsc inc | cpp/locale/dsc LC_categories}}
 
{{dsc inc | cpp/locale/dsc LC_categories}}

2018年4月29日 (日) 05:57時点における最新版

 
 
 
ヘッダ <clocale> で定義
char* setlocale( int category, const char* locale);

setlocale 関数は指定されたシステムロケールまたはその一部を新しい C のロケールとして設定します。 変更は次に setlocale を呼ぶまで有効で、すべてのロケール対応の C のライブラリ関数の実行に影響を与えます。 locale がヌルポインタの場合、 setlocale は現在の C のロケールを変更せずに問い合わせます。

目次

[編集] 引数

category - ロケールカテゴリ識別子、 LC_xxx マクロのひとつ。 0でも構いません
locale - システム固有のロケール識別子。 ユーザ推奨ロケールのためには ""、最小限のロケールのためには "C" を指定できます

[編集] 戻り値

変更 (もしあれば) を適用した後の C のロケールを識別するヌル終端ナロー文字列を指すポインタ、または失敗した場合はヌルポインタ。

std::setlocale のこの呼び出しで使用されたカテゴリと返された文字列のコピーは、ロケールをこの呼び出しの終わりの状態に復元するために後にプログラムで使用することができます。

[編集] ノート

プログラムの開始時、いかなるユーザのコードも実行される前に、 std::setlocale(LC_ALL, "C"); と同等の処理が実行されます。

戻り値の型は char* ですが、その指している先の文字を変更することは未定義動作です。

setlocale はロケール依存の関数の実行に影響を与えるグローバルな状態を変更するため、あるスレッドで 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,