|
Blue Forest http://www.lslnet.com at 10:18 on June 6, 2006
Unicode and locale
Recently, I have in the development process, he encountered a unicode string encoding.
How to deal with these troubled string a lot of time.
Originally used the WCHAR and WideCharToMultiByte. Later, taking account of the transplant.
Use a wchar_t, and wprintf.
It should be said wprintf exporting unicode string is no problem, but if we really wrote,
Screen is not.
Check a lot of information, understand that this game and the locale. If the current locale is C, and the Spanish environment quite right, then the Eastern unicode is not out of print.
Chinese as the only locale only after success.
The following procedures are aimed at Windows, it can be transplanted into Unix environment, I have not yet tried.
X-----------------------------------------X
#include "Stdafx.h"
#include "Locale.h>;
#include "Malloc.h>;
Int main (int argc, char* argv[])
{
Char *a;
= (Char *) malloc (100);
Setlocale (LC_ALL, "chinese");
Wchar_t t[20]=L "Happy New Year";
A=setlocale (LC_ALL, NULL);
Printf ( "Hello World! %s\n", a);
Wprintf (L "%s\n", t);
Return 0
} |
| |