c++utf-8character-encodingascii

Convert UTF-8 to ANSI in C++


I can't find an answer to this question anywhere.

How can I convert a string from UTF-8 to ANSI (extended ASCII) in C++?


Solution

  • Generally, one uses libiconv (webpage), which is portable and runs on most platforms. As KerrekSB mentioned, you will get in deep trouble if you think of a character set as "extended ASCII" -- I'm sure there are at least a hundred character sets that could be called "extended ASCII", including UTF-8.

    Also, make sure you know which encoding you want: ISO-8859-1 or CP1252. The Windows version replaces the C1 control codes with additional printing characters.