Rewrite txt file into other encoding

1k views Asked by At

I have a problem. I want to rewrite txt file into other txt file, but with other encoding. I must implement conversion to Unicode, iso-8859 and windows-1250.

I must write it in c++. Can anyone help me with this topic? How to start coding this?

Best regards!

2

There are 2 answers

2
MSalters On BEST ANSWER

Windows is perfectly capable of doing string conversions for you. Read data from the source file and pass it to MultiByteToWideChar specifying the source codepage, then pass that output to WideCharToMultiByte specifying the target codepage and write that output to the target file.

BTW, next question state up front that you're working on Windows only. Don't put useful information like that in a comment.

1
Miguel On

I would start by getting a good in-depth knowledge of this encoding formats, I would create some encoding conversion tables, and convert byte by byte. Also, it sounds like you are going to be dealing with different operating systems, so keep an eye out for endianness.

Here's a good link to get you started Encoding for Programmers.

EDT#1: Here is another link that goes a little more in depth on the subject of character encoding in windows. Here you can find functions and macros that can help you building your application.