回答編集履歴
1
追記
answer
CHANGED
@@ -26,4 +26,44 @@
|
|
26
26
|
setlocale(LC_ALL, "");
|
27
27
|
foo("あのイーハトーヴォの透き通った風");
|
28
28
|
}
|
29
|
+
```
|
30
|
+
|
31
|
+
---
|
32
|
+
**追記**
|
33
|
+
|
34
|
+
面倒な解放をしたくない場合(C++11以降用)
|
35
|
+
SJIS決め打ちするとmblenは1~2byteなので'\0'含めて3byteを固定で持てばいい
|
36
|
+
|
37
|
+
```cpp
|
38
|
+
#include <vector>
|
39
|
+
#include <array>
|
40
|
+
#include <iostream>
|
41
|
+
#include <cstring>
|
42
|
+
#include <cstdlib>
|
43
|
+
#include <clocale>
|
44
|
+
|
45
|
+
template<size_t N>
|
46
|
+
std::ostream& operator<<(std::ostream& os, const std::array<char, N>& ary)
|
47
|
+
{ os << ary.data();return os; }
|
48
|
+
|
49
|
+
void foo(const char* String) {
|
50
|
+
std::vector<std::array<char, 3>> vec;
|
51
|
+
setlocale(LC_ALL, "");
|
52
|
+
for (int i = 0; String[i] != '\0';) {
|
53
|
+
int len = mblen(&String[i], MB_CUR_MAX);
|
54
|
+
auto buf = std::array<char, 3>{0};
|
55
|
+
memcpy(buf.data(), &String[i], len);
|
56
|
+
vec.push_back(std::move(buf));
|
57
|
+
i+=len;
|
58
|
+
}
|
59
|
+
|
60
|
+
for (const auto &c : vec) {
|
61
|
+
std::cout << c << ",";
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
|
66
|
+
int main() {
|
67
|
+
foo("あのイーハトーヴォの透き通った風");
|
68
|
+
}
|
29
69
|
```
|