Skip to content

Commit 4329bd5

Browse files
committed
setlocale: 関数ページを追加
1 parent 195f008 commit 4329bd5

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

reference/clocale/setlocale.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# setlocale
2+
* clocale[meta header]
3+
* std[meta namespace]
4+
* function[meta id-type]
5+
6+
```cpp
7+
namespace std {
8+
char* setlocale(int category, const char* locale);
9+
}
10+
```
11+
12+
## 概要
13+
指定したカテゴリのロケールを設定、または現在のロケールを取得する。
14+
15+
指定できるロケール文字列は[以下のページ](/article/platform/locales.md)である。
16+
17+
## 引数
18+
- `category`:設定対象のカテゴリ。`LC_ALL`,`LC_CTYPE`などのマクロを使用。
19+
- `locale`:
20+
* "C":標準のCロケール
21+
* "":環境依存のデフォルトロケール
22+
* `NULL`:現在のロケールを取得するだけ
23+
24+
## 戻り値
25+
成功時は設定されたロケール名(文字列)、失敗時は`NULL`。
26+
27+
## 例
28+
```cpp example
29+
#include <iostream>
30+
#include <clocale>
31+
32+
int main(){
33+
// 日本語ロケールに設定
34+
if (!std::setlocale(LC_ALL, "ja_JP.UTF-8")) {
35+
std::cerr << "Failed to set locale\n";
36+
return 1;
37+
}
38+
39+
// 現在の全カテゴリのロケールを取得
40+
std::cout << "Current locale: " << std::setlocale(LC_ALL, NULL) << "\n";
41+
42+
// 数値カテゴリだけ確認
43+
std::cout << "Numeric locale: " << std::setlocale(LC_NUMERIC, NULL) << "\n";
44+
}
45+
46+
```
47+
48+
### 出力
49+
```
50+
Current locale: ja_JP.UTF-8
51+
Numeric locale: ja_JP.UTF-8
52+
```
53+
54+
## 関連項目
55+
- [ ロケール文字一覧 ](/article/platform/locales.md)
56+
- [ `std::locale` ](/reference/locale/locale.md)

0 commit comments

Comments
 (0)