Sign in to follow this  

Unicode in VS .NET 2005

This topic is 4163 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm currently converting a C++ .NET 2005 application to unicode. Parts of the program write out formatted files - do I need to convert, for example, fprintf() to fwprintf() if the application is to work correctly on Unicode systems? In any case, only English text will be written to file. As I understand it, _wfopen, fwprintf, etc. only need to be used if you want to actually output unicode data to a file... is this correct? Any help would be much appreciated. James.

Share this post


Link to post
Share on other sites
Abstract stuff:
Unicode and wchar is a quite complicated but not really a complex topic. You have characters as program entities (at least in 2 different types: char and wchar_t), characters as bytes of a file, character sets as abstract entites and encodings.

An encoding is a bidirectional map character of a character set<->bytes. To write a character you look up it's encoding and write that to the file, to read a character you read bytes until you find a matching character in the encoding (or discover that this sequence of bytes is no valid encoding).


concrete stuff:
A file doesn't contain characters, it contains bytes. There are only 2 things you need to take care of:
1) read and write a file with the same encoding
2) you can only use encodings that support all characters you want to write
both together make sure that you end up with the same characters.

Just write the file in whatever way you want (both fwprintf and fprintf work for english text) and read it in the corresponding way to make sure the right encoding is used while reading. If you read chars you should to convert them to wchar_t before returning the string read, so that the main part of the program only has to handle one type of character/one type of string.

Share this post


Link to post
Share on other sites
Unicode can be a fairly complex subject, especially when dealing with backward compatibility.

In your case, it looks like the problem is knowing how to output to files. I would recommend you actually output in Unicode, using fwprintf. This way, you don't have to convert to ANSI strings before writing to the file. And the day the output is not in plain english, you'll be very happy!

Share this post


Link to post
Share on other sites

This topic is 4163 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this