[英]Read Unicode UTF-32 file into wstring
对于UTF-16,我们可以同时读取并将其转换为wchar
。 例如,
std::wifstream* file = new std::wifstream(name, ifstream::binary);
locale lo = locale(file->getloc(), new std::codecvt_utf16<wchar_t, 0x10ffff, std::little_endian>);
file->imbue(lo);
对于UTF-32输入,我该怎么做?
您可能要使用经典的C ++模式,在堆栈上分配wifstream
而不是堆( new
):
std::wifstream* file = new std::wifstream(name, ifstream::binary);
std::wifstream file(name, ifstream::binary);
对于编解码器部分,我将尝试使用std::codecvt_utf16<char32_t>
。
PS注意wchar_t
在不同平台上可以具有不同的大小(16位,32位)。 因此,它可能是更好地为您使用std::u16string
为UTF-16和std::u32string
为UTF-32。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.