0

I have an array of approximately 400 UTF-8 bytes. How can I display the corresponding text? It almost certainly contains several emojis, along with ASCII.

Platform is Windows with Visual C++, but I can switch to macOS or Linux if necessary. Happy to use a 3rd party library too.

Clarification: It's a console application, so I'd like to display the result in a console. I can use Windows Terminal instead. Looks like MultiByteToWideChar is what I need.

royco
  • 5,409
  • 13
  • 60
  • 84
  • "*display*" how/where exactly? Outside the console it's platform dependent, and inside the console it can be tricky on most platforms. – dxiv May 28 '20 at 00:46
  • 2
    Write to a utf-8 compatible output device, e.g. [windows terminal](https://github.com/microsoft/terminal). It's not really a C++ question unless you are contemplating rendering fonts yourself or something? – M.M May 28 '20 at 01:04
  • 1
    Display it where? Since I don't know the details you could convert the `UTF8` to `UTF16` using `MultiByteToWideChar` and then use `std::wcout` or some Win32 `W` function to do whatever it is you're trying to do – WBuck May 28 '20 at 02:20
  • 1
    A Windows console can't really display Unicode using the stdio interface. You'll need to call some specific Windows API functions for the console. – Mark Ransom May 28 '20 at 02:44
  • @MarkRansom The Windows console can technically display Unicode via the standard streams, though it takes some hoops. See [this answer](https://stackoverflow.com/a/45461313) for example to another question [wchar_t* with UTF8 chars in MSVC](https://stackoverflow.com/questions/45449346/wchar-t-with-utf8-chars-in-msvc). – dxiv May 28 '20 at 03:02
  • As @M.M pointed out, he could use the `Windows Terminal` instead and just display the `UTF8` as is. That of course is assuming that he needs this for personal reasons ie not depending on a client having the `Windows Terminal` installed. – WBuck May 28 '20 at 03:08
  • regarding the "Clarification", if you use Windows Terminal then you do NOT use multibytetowidechar , since that terminal can display UTF-8 – M.M May 28 '20 at 03:17

0 Answers0