Read *.txt file with German text, show it in my GUI -- characters with umlauts not correct

440 Views Asked by At

My world is: MFC, Visual Studio C++, using MBCS character set. Generally using CString as my favorite string type, but sometimes std:string as well.

I can put German words in my string table and they show up in the GUI just fine - full of lovely umlauts and other accents. But if I have a *.txt file containing German text with umlauts, when I read it in (using CStdioFile) and then show it in the GUI, the umlauts and other special characters do not print nicely, instead things like für showing up (should be "fur" with an umlaut on the u).

How can I read a *.txt file of German text and show it in the GUI? Thought this was simple. I could swear I've done it before without issue. Thanks in advance for your help!

1

There are 1 best solutions below

0
On

The problem is probably that your input file is encoded in UTF-8, whereas your viewer is interpreting it as a single-byte encoding using code page Windows-1252.

When encoding the string

für

in UTF-8, you get the following bytes:

0x66 0xc3 0xbc 0x72

The characters f and r are each encoded into one byte, whereas the character ü is encoded into two bytes.

These bytes correspond to

für

in code page Windows-1252.

In your question, you stated that für is the output that you are getting for the string für. Therefore, what I have stated seems to be the most obvious explanation for the output.