gpt4 book ai didi

c++ - 十六进制转unicode字符

转载 作者:行者123 更新时间:2023-11-28 08:23:50 25 4
gpt4 key购买 nike

在 C++ 中,我想将十六进制字符串作为 unicode 字符保存到文件中例如:0x4E3B 保存到文件 ---> 主

如有任何建议或想法,我们将不胜感激。

最佳答案

什么编码?我假设是 UTF-8。

什么平台?

如果你在Linux下那么

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;

但是,如果您需要 Windows,那就完全不同了:

您需要将代码点转换为 UTF-8。很多方法。如果大于0xFFFF,则将其转换为UTF-16,然后搜索如何使用WideCharToMultiByte,然后保存到文件。

关于c++ - 十六进制转unicode字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4772959/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com