我正在使用以下代码将字符串从 转换unsigned char*
为const wchar_t*
. 我得到的错误是只有几个单词被正确转换,而其余的都是乱码。
代码
unsigned char* temp = fileUtils->getFileData("levels.json", "r", &size);
const char* temp1 = reinterpret_cast<const char*>(temp);
size_t len = mbstowcs(nullptr, &temp1[0], 0);
if (len == -1) {
} else {
wchar_t* levelData = new wchar_t();
mbstowcs(&levelData[0], &temp1[0], size*10);
}
输出
temp1 = "[{"scaleFactor": 1}][{"scaleFactor": 2}][{"scaleFactor": 3}][{"scaleFactor": 4}][{"scaleFactor": 5}][{"scaleFactor": 6}][{"scaleFactor": 7}][{"scaleFactor": 8}][{"scaleFactor": 9}][{"scaleFactor": 10}]"
levelData = "[{"scaleFactor": 1}][{"scaleFactor": 2}][{"scaleFactor": 3}][{"scaleFactor": 4}][{"scaleFactor": 5}][{"scaleFactor": 6}][{"scaleFactor": 7}][{"s慣敬慆瑣牯㨢㠠嵽筛猢慣敬慆瑣牯㨢㤠嵽筛猢慣敬慆瑣牯㨢ㄠ細ﵝ﷽ꮫꮫꮫﺫﻮ"