Unicode

Programming, for all ages and all languages.
Post Reply
Guest

Unicode

Post by Guest »

Hi,

Just wondering if anyone can tell me where I can find an in depth article on using unicode in c++ apps.

I want to make it completely unicode compatible, also I need to know what unicode c functions to substitute for the standard ansi string functions (string.h).

If it is not that difficult then could some just tell me here.

I know that strings should be placed inside the _T() macro, and I am supposed to use TCHAR instead of char but what includes do I use and what c functions do I use to manage the strings.

thanks.
ark

Re:Unicode

Post by ark »

if you've got TCHAR's, then include tchar.h and use those string manipulation functions.

they generally follow this naming rule...if the function starts with str when you use the regular char data type, then the TCHAR equivalent will start with _tcs instead, so:

_tcscpy equates to strcpy
_tcsncpy equates to strncpy
_tcscat equates to strcat

and so on

The names of all the TCHAR equivalents for string functions can be seen if you look at tchar.h.

You can see that toupper translates to totupper, and so on.

Also, I think it may be better to get in the habit of using the TEXT macro instead of _T, because I think _T is only defined when you're using MFC, whereas TEXT is defined when using regular old windows.h and when using MFC.
ark

Re:Unicode

Post by ark »

incidentally, if you are using MFC, then the CString class uses TCHAR as its base type, so it is already Unicode compatible.
Tim

Re:Unicode

Post by Tim »

Another good trick is:

Code: Select all

#include <tchar.h>
#include <string>

typedef std::basic_string<TCHAR> tstring;
This gives you a Unicode/ANSI std::string class.
Guest

Re:Unicode

Post by Guest »

Ok, thanks for your help. :D
Post Reply