将光标移到/点击文章中的句子上,可以查看译文。      显示繁体中文内容    显示简体中文内容

c++ - Deprecated header <codecvt> replacement
C++ 不推荐的标头 <codecvt> 替换

148 4

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?

(Don't mind using Boost at all, but other than that i prefer to stay as close to standard library as possible. )

时间: 原作者:

100 0

std::codecvt template from <locale> itself isn't deprecated.for UTF-8 to UTF-16, there is stillstd::codecvt<char16_t, char, std::mbstate_t>specialization.

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.

So, as Bolas already answered :Implement it yourself (or you can use a third party library, as always) or keep using the deprecated API.

原作者:
61 1

don't worry about that.

According to the same information source :

this library component should be retired to Annex D, along side, until a suitable replacement is standardized.

So, you can still use it utill a new standardized, more-secure version is done.

原作者:
143 3

The new way is... you write it yourself.or just rely on deprecated functionality.Hopefully, the standards committee won't actually remove codecvt until there is a functioning replacement.

But at present, there isn't one.

原作者:
...