回答編集履歴
1
追記
test
CHANGED
@@ -55,3 +55,83 @@
|
|
55
55
|
}
|
56
56
|
|
57
57
|
```
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
---
|
62
|
+
|
63
|
+
**追記**
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
面倒な解放をしたくない場合(C++11以降用)
|
68
|
+
|
69
|
+
SJIS決め打ちするとmblenは1~2byteなので'\0'含めて3byteを固定で持てばいい
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
```cpp
|
74
|
+
|
75
|
+
#include <vector>
|
76
|
+
|
77
|
+
#include <array>
|
78
|
+
|
79
|
+
#include <iostream>
|
80
|
+
|
81
|
+
#include <cstring>
|
82
|
+
|
83
|
+
#include <cstdlib>
|
84
|
+
|
85
|
+
#include <clocale>
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
template<size_t N>
|
90
|
+
|
91
|
+
std::ostream& operator<<(std::ostream& os, const std::array<char, N>& ary)
|
92
|
+
|
93
|
+
{ os << ary.data();return os; }
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
void foo(const char* String) {
|
98
|
+
|
99
|
+
std::vector<std::array<char, 3>> vec;
|
100
|
+
|
101
|
+
setlocale(LC_ALL, "");
|
102
|
+
|
103
|
+
for (int i = 0; String[i] != '\0';) {
|
104
|
+
|
105
|
+
int len = mblen(&String[i], MB_CUR_MAX);
|
106
|
+
|
107
|
+
auto buf = std::array<char, 3>{0};
|
108
|
+
|
109
|
+
memcpy(buf.data(), &String[i], len);
|
110
|
+
|
111
|
+
vec.push_back(std::move(buf));
|
112
|
+
|
113
|
+
i+=len;
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
for (const auto &c : vec) {
|
120
|
+
|
121
|
+
std::cout << c << ",";
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
int main() {
|
132
|
+
|
133
|
+
foo("あのイーハトーヴォの透き通った風");
|
134
|
+
|
135
|
+
}
|
136
|
+
|
137
|
+
```
|