0

I am trying to write a function to convert a const char16_* to a const wchar_t* to use it in wprintf later on:

const wchar_t* wchart_from_char16(const char16_t*) {
   ???
}

int main(){
  const char16_t* my = u"The Text I want to print";
  const wchar_t* ret = wchart_from_char16(my);
  wprintf(L"The Text is is: %ls ", ret);
 }

How can I do this using codecvt ? This needs to work cross platform

user3443063
  • 1,455
  • 4
  • 23
  • 37
  • https://stackoverflow.com/questions/71218932/c-convert-wchar-t-to-char16-t-and-back https://stackoverflow.com/questions/7232710/convert-between-string-u16string-u32string – KamilCuk Jul 03 '23 at 12:33
  • Thanks KamilCouk, I tried to understand that but couldn`t. And I do not want to use UTF 8. – user3443063 Jul 03 '23 at 13:02
  • Is this under Windows? – i486 Jul 03 '23 at 13:08
  • I will suspect ` do not want to use UTF 8` and `can I do this using codecvt ?` are in conflict. If you want to convert utf-16 to utf-32, use an external library like libunistring or icu. If you want to convert char16_t to wchar_t, you will have to convert to char16_t to multibyte string and then multibyte string to wchar_t (at least in C). – KamilCuk Jul 03 '23 at 13:24
  • The cross-platform part will hit a real hurdle in that `wchar_t` has difference sizes on different platforms. That's probably why we have `char16_t` in the first place! – BoP Jul 03 '23 at 14:02

0 Answers0