不建议使用的标头< codecvt>替换 [英] Deprecated header <codecvt> replacement
问题描述
一些前景:我的任务需要将UTF-8 XML文件转换为UTF-16(当然具有正确的标头).因此,我搜索了将UTF-8转换为UTF-16的常用方法,发现应该使用<codecvt>
中的模板.
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<char16_t, char, std::mbstate_t>
专业化.
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.
这篇关于不建议使用的标头< codecvt>替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!