开发者

converting array of bytes to UTF-8 unicode

I have a file saved as UTF-8, and i'm reading i开发者_如何转开发t like this:

ReadFile(hFile, pContents, pFile->nFileSize, &dwRead, NULL);

(pContents is a BYTE* of size nFileSize)

its just a small file with 100 bytes or so, contains text which i want to read into memory in wchar_t* format, so i can set the text of edit and static controls with the unicode text.

How can i convert the bytes to UTF-8?

edit (i don't want to use fstream or wfstream)


  • MultiByteToWideChar to convert from UTF-8 to UTF-16 (wchar_t).
  • WideCharToMuliByte to convert from UTF-16 to UTF-8.


If the file is in UTF-8 and you read it into an array.
Then it is still in UTF-8 format and you don;t need to do anything.


int res2 = WideCharToMultiByte(CP_UTF8, 0, tempBuf.c_str(), -1, 
                               multiByteBuf, lengthOfInputString, NULL, NULL);
int res = MultiByteToWideChar(CP_UTF8, 0, buf, -1, wcharBuf, lengthOfInputString);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜