不推荐使用的标头 <codecvt>替代品
有点前景:我的任务需要将 UTF-8 XML 文件转换为 UTF-16(当然还有适当的标头).因此,我搜索了将 UTF-8 转换为 UTF-16 的常用方法,发现应该使用
中的模板.
A bit of foreground: my task required converting UTF-8 XML file to UTF-16 (with proper header, of course). And so I searched about usual ways of converting UTF-8 to UTF-16, and found out that one should use templates from <codecvt>
.
但是现在当它已弃用时,我想知道什么是新的常用方法同样的任务?
But now when it is deprecated, I wonder what is the new common way of doing the same task?
(完全不介意使用 Boost,但除此之外,我更喜欢尽可能接近标准库.)
(Don't mind using Boost at all, but other than that I prefer to stay as close to standard library as possible.)
推荐答案
std::codecvt
模板来自
本身并没有被弃用.对于 UTF-8 到 UTF-16,仍然有 std::codecvt
特化.
std::codecvt
template from <locale>
itself isn't deprecated. For UTF-8 to UTF-16, there is still std::codecvt<char16_t, char, std::mbstate_t>
specialization.
但是,由于 std::wstring_convert
和 std::wbuffer_convert
与标准转换方面一起被弃用,因此没有任何简单的方法可以使用方面.
However, since std::wstring_convert
and std::wbuffer_convert
are deprecated along with the standard conversion facets, there isn't any easy way to convert strings using the facets.
因此,正如 Bolas 已经回答的那样:自己实现它(或者您可以像往常一样使用第三方库)或继续使用已弃用的 API.
So, as Bolas already answered: Implement it yourself (or you can use a third party library, as always) or keep using the deprecated API.
相关文章