开发者

Convert hexadecimal into unicode character

In开发者_如何转开发 C++, I would like to save hexadecimal string into file as unicode character Ex: 0x4E3B save to file ---> 主

Any suggestions or ideas are appreciated.


What encoding? I assume UTF-8.

What platform?

If you under Linux then

std::locale loc("en_US.UTF-8"); // or "" for system default
std::wofstream file;
file.imbue(loc); // make the UTF-8 locale for the stream as default
file.open("file.txt");   
wchar_t cp = 0x4E3B;
file << cp;

However if you need Windows it is quite different story:

You need to convert code point to UTF-8. Many ways. If it is bigger then 0xFFFF then convert it to UTF-16 and then search how to use WideCharToMultiByte, and then save to file.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜