Deprecated header lt;codecvtgt; replacement(不推荐使用的标头 lt;codecvtgt;替代品)
问题描述
有点前景:我的任务需要将 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.
这篇关于不推荐使用的标头 <codecvt>替代品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:不推荐使用的标头 <codecvt>替代品


基础教程推荐
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- CString 到 char* 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05