Skip to content

Commit 0b61755

Browse files
committed
mblenのサンプルコード : ロケールを毎回設定すると重いので文字数計算の外にだした
1 parent f73e9f6 commit 0b61755

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

reference/cstdlib/mblen.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ int main() {
5151
#include <clocale>
5252

5353
int count_chars_mblen(const char* s) {
54-
std::setlocale(LC_ALL, "ja_JP.UTF-8");
5554
int count = 0;
5655
size_t i = 0;
5756
while (s[i] != '\0') {
@@ -66,6 +65,8 @@ int count_chars_mblen(const char* s) {
6665
}
6766

6867
int main() {
68+
std::setlocale(LC_ALL, "ja_JP.UTF-8");
69+
6970
const char* str = "こんにちは世界";
7071
std::cout << "文字列: " << str << "\n";
7172
std::cout << "文字数: " << count_chars_mblen(str) << "\n";

0 commit comments

Comments
 (0)