1

I am trying to read a .txt file which is encoded with UTF-16 LE BOM, and trying to display it in my C++ GUI. But the only options I found online are deprecated.

image

Stuff I tried:

Reading UTF-16 file in c++

How to set file encoding format to UTF8 in C++

How do I print UTF-8 from c++ console application on Windows

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Zein
  • 11
  • 2
  • Do you understand how UTF-16 LE encoding works? Do you understand how UTF-8 encoding works? Have you tried simply writing your own tiny little function to convert one to the other? – Sam Varshavchik Nov 11 '22 at 22:39
  • Sadly i never worked with encoding, so i know a little bit about the difference, but thats all, so sadly i am probably not able to come up with a clever function by myself. First time i am working with encoding. – Zein Nov 11 '22 at 22:43
  • Lots of options: https://stackoverflow.com/questions/265370/utf-16-to-utf-8-conversion-for-scripting-in-windows – Eljay Nov 11 '22 at 22:46
  • That's ok, there's a first time for everyone. When I had to do something similar a little bit of searching found plenty of reference material that explained how these encodings work. In my case it was UTF-32 to UTF-8, but the difference are minor. An hour or two reading the Wikipedia pages, and mission accomplished. – Sam Varshavchik Nov 11 '22 at 22:46
  • There are tons of questions on StackOverflow showing how to convert between UTF encodings, some using OS APIs, some using 3rd party libraries, some using manual coding. You should search around before asking a new question. In any case, what EXACTLY did you try? What does your code look like? What "deprecated" options are you referring to, exactly? Be specific. – Remy Lebeau Nov 11 '22 at 22:46
  • @RemyLebeau I searched not only on StackOverflow before, but the only threads i was able to find where ones with results which use deprecated stuff. So if you found an example which is not, it would be awesome if you can link it here. – Zein Nov 11 '22 at 22:48
  • @Eljay i will take a look at that one even though i was looking for a native c++ option, as i never worked with encoding before and want to understand it in depth. – Zein Nov 11 '22 at 22:51
  • @RemyLebeau Most threads i found are referring to codecvt_utf8, codecvt_utf16, codecvt_utf8_utf16, which is deprecated. https://en.cppreference.com/w/cpp/locale/codecvt_utf8_utf16 i linked the code i already tried on the original post . – Zein Nov 11 '22 at 22:53
  • 1
    @Zein Just because they are deprecated doesn't mean they stop working. You can still use the `codecvt` stuff right now. In any case, converting between UTFs is trivial to code manually if you understand how the UTFs actually work at the binary level. Or, you could just let a library like ICU or ICONV do the work for you – Remy Lebeau Nov 11 '22 at 23:00

0 Answers0