I want to convert the data type char16_t
to utf8, and I have written the following code to do that:
// utf16 String
char16_t *wchs = u"UTF16 string";
// A converter object
wstring_convert<codecvt_utf8_utf16<char16_t>, char16_t> conv;
// Convert from utf16 to utf8
string str = conv.to_bytes(wchs);
// print the UTF-16 string after converting to UTF-8
cout << str << endl;
The previous code doesn't work in visual studio whether 2015 or 2017, specifically with "char16_t" data type and gives me an error:
error LNK2001: unresolved external symbol "public: static class std::locale::id std::codecvt<char16_t,char,struct _Mbstatet>::id" (?id@?$codecvt@_SDU_Mbstatet@@@std@@2V0locale@2@A)
,
but works well in the GCC compiler.
Why that happened and how to solve that problem?