We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a4b0b47 commit bc2182dCopy full SHA for bc2182d
1 file changed
reference/cstdlib/mblen.md
@@ -33,7 +33,7 @@ namespace std {
33
int main() {
34
std::setlocale(LC_ALL, "ja_JP.UTF-8");
35
const char *str = "こんにちは";
36
- int result = std::mblen(str, MB_CUR_MAX);
+ int result = std::mblen(str, std::strlen(s));
37
std::cout << result << std::endl;
38
return 0;
39
}
@@ -56,8 +56,9 @@ int count_chars_mblen(const char* s) {
56
57
int count = 0;
58
std::size_t i = 0;
59
- while (s[i] != '\0') {
60
- int len = std::mblen(&s[i], MB_CUR_MAX);
+ std::size_t bytes = std::strlen(s);
+ while (i < bytes) {
61
+ int len = std::mblen(&s[i], bytes - i);
62
if (len < 0) {
63
len = 1;
64
0 commit comments