C++ ucs2和utf8之间的转换

C++ ucs2和utf8之间的转换,c++,visual-studio-2015,utf-8,c++14,ucs2,C++,Visual Studio 2015,Utf 8,C++14,Ucs2,我正在尝试在utf8和ucs2之间进行转换 #include <codecvt> std::wstring_convert<std::codecvt_utf8<char16_t>, char16_t> ucs2conv; std::u16string ucs2 = ucs2conv.from_bytes(utf8_string); std::string utf8_new = ucs2conv.to_bytes(ucs2); #包括 std::wstrin

我正在尝试在
utf8
ucs2
之间进行转换

#include <codecvt> 
std::wstring_convert<std::codecvt_utf8<char16_t>, char16_t> ucs2conv;
std::u16string ucs2 = ucs2conv.from_bytes(utf8_string);
std::string utf8_new = ucs2conv.to_bytes(ucs2);
#包括
std::wstring_convert UCS2 conv;
std::u16string ucs2=ucs2conv.from_字节(utf8_字符串);
std::string utf8_new=ucs2conv.to_字节(ucs2);
不幸的是
microsoft vs2015
在使用
codecvt
时有一个错误。导致以下错误:

错误LNK2001未解析的外部符号“\uu declspec(dllimport)public:静态类std::locale::id std::codecvt::id”


有人知道如何在
linux
上以同样可行的方式解决这个bug吗?

只需使用
wchar\u t
(这保证与VC++的
char16\u t
大小相同)和
std::wstring
@DevSolar实际上,这是C++11以后的改进之一。现在有UTF16和UTF32类型和字符串(
char16\u t1
char32\u t
u16string
u32string
)。唯一的“孔”是UTF8。UTF8文本可用,但UTF8字符串使用了
char
string
类型@PanagiotisKanavos:新类型很好,但只使用了98%。例如,合成/分解/规范化(据我所知)也没有涉及。@PanagiotisKanavos:不幸的是,该缺陷在VC++2017中没有修复。(阅读Steve Wishnousky对你链接的bug的评论。)@ildjarn诅咒!那他们为什么把它当作固定的呢?我想知道VC++2017中的Linux负载是否有不同的工作方式。