如何将linux中编写的std::wstring读入windows
我们有一个可以在 Windows 和 Linux 上运行的程序。它将二进制形式的 std::wstrings 写入文件。我们需要能够将 Linux 写入的文件读入 Windows。我们将字符串写为 wchar_t 列表。在linux上每个wchar_t占用4个字节。在 Windows 上,每个 wchar_t 占用 2 个字节。
当将linux写入的文件读入Windows时,如何将4字节wchar_t放入2字节wchar_t中?
谢谢, 亚当
We have a program which runs on Windows and Linux. It writes out std::wstrings in binary to a file. We need to be able to read in files written from linux into windows. We write out strings as a list of wchar_t. On linux each wchar_t occupies 4 bytes. On Windows each wchar_t occupies 2 bytes.
When reading the file written by linux into Windows how can one take the four byte wchar_t and put it into the 2 byte wchar_t?
Thanks,
Adam
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 UTF8-CPP 轻松将文件从 UTF-32 转换为 UTF-16:
不幸的是没有 < code>utf8::utf32to16,尽管也许应该有。
You can use UTF8-CPP to easily convert the file from UTF-32 to UTF-16:
Unfortunately there is no
utf8::utf32to16
, though perhaps there should be.假设 Linux 代码以 UTF-32 格式写入,您必须编写一些代码将字符串转换为 UTF-16,这是 Windows 上使用的 Unicode 编码。 wstring 无法帮助你解决这个问题。转换为 UTF-16 后,您可以使用 wchar_t 将其存储在 Windows 上的 wstring 中。
Assuming the Linux code is writing out in UTF-32 format, you'll have to write some code to convert the string to UTF-16 which is the Unicode encoding used on Windows. wstring can't help you with this. Once you have converted to UTF-16, you can store in a wstring on Windows using wchar_t.