Page 1 of 1

Unicode

Posted: Wed Jan 22, 2003 9:52 pm
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.

Re:Unicode

Posted: Thu Jan 23, 2003 4:39 pm
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.

Re:Unicode

Posted: Thu Jan 23, 2003 4:42 pm
by ark
incidentally, if you are using MFC, then the CString class uses TCHAR as its base type, so it is already Unicode compatible.

Re:Unicode

Posted: Thu Jan 23, 2003 7:04 pm
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.

Re:Unicode

Posted: Thu Jan 23, 2003 9:11 pm
by Guest
Ok, thanks for your help. :D