不建议使用的标头< codecvt>替换 [英] Deprecated header <codecvt> replacement

查看:293
本文介绍了不建议使用的标头< codecvt>替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一些前景:我的任务需要将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_convertstd::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.

这篇关于不建议使用的标头&lt; codecvt&gt;替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆