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.
Unicode
Re:Unicode
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.
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
incidentally, if you are using MFC, then the CString class uses TCHAR as its base type, so it is already Unicode compatible.
Re:Unicode
Another good trick is:
This gives you a Unicode/ANSI std::string class.
Code: Select all
#include <tchar.h>
#include <string>
typedef std::basic_string<TCHAR> tstring;