Skip to content

Commit 8efeaf3

Browse files
committed
Add new post cstdlib/mblen
1 parent 1ed3f7d commit 8efeaf3

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

reference/cstdlib/mblen.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# mblen
2+
* cstdlib[meta header]
3+
* std[meta namespace]
4+
* function[meta id-type]
5+
6+
```cpp
7+
namespace std {
8+
int mblen(const char* str, size_t n);
9+
}
10+
```
11+
12+
## 概要
13+
マルチバイト文字列の先頭の文字が占めるバイト数を返す。
14+
15+
この関数は現在のロケールに依存してマルチバイト文字を解釈する。
16+
n は解析に使用する最大バイト数を指定する。
17+
18+
## 戻り値
19+
- 正常に動作する場合、文字の占めるバイト数を返す。
20+
- `str`が`nullptr`の時、内部状態を初期化し`0`を返す。
21+
- 無効な文字列、または`n`が不足している場合、`-1`を返す。
22+
23+
## 例
24+
```cpp example
25+
#include <iostream>
26+
#include <cstdlib>
27+
#include <clocale>
28+
29+
int main() {
30+
std::setlocale(LC_ALL, "ja_JP.UTF-8");
31+
const char *str = "こんにちは";
32+
int result = std::mblen(str, MB_CUR_MAX);
33+
std::cout << result << std::endl;
34+
return 0;
35+
}
36+
```
37+
38+
### 出力例
39+
```
40+
3
41+
```

0 commit comments

Comments
 (0)