How to output UTF-8/UTF-16 string in VS?
-
;P;P;PHi, I'm dev in China. I want to output some string of Chinese in unicode format(UTF-8/UTF-16). So in VS2003, I write code like this to test: int _tmain(int argc, _TCHAR* argv[]) { _TCHAR* buffer = L"汉"; unsigned char* uP = (unsigned char*)buffer; return 0; } I found that the pointer 'uP' have this value: uP : 186 (BA) uP+1: 0 uP+2: 186 (BA) uP+3: 0 The unicode of '汉' is: 6C 49 The Chinese code page (GBK) in windows of '汉' is : BA BA So, the internal code in program only extand BA to BA 00 I test the code in VS2005 again, however, the internal code became 6C 49, is correct. I don't know why.:(( Remy Zhu
-
;P;P;PHi, I'm dev in China. I want to output some string of Chinese in unicode format(UTF-8/UTF-16). So in VS2003, I write code like this to test: int _tmain(int argc, _TCHAR* argv[]) { _TCHAR* buffer = L"汉"; unsigned char* uP = (unsigned char*)buffer; return 0; } I found that the pointer 'uP' have this value: uP : 186 (BA) uP+1: 0 uP+2: 186 (BA) uP+3: 0 The unicode of '汉' is: 6C 49 The Chinese code page (GBK) in windows of '汉' is : BA BA So, the internal code in program only extand BA to BA 00 I test the code in VS2005 again, however, the internal code became 6C 49, is correct. I don't know why.:(( Remy Zhu
You shouldn't use characters outside of the ASCII range in source code, because (as you saw) the parser may interpret the bytes differently according to the code page and character set that the app uses. Use the
\x
notation for the string literal:L"\x6c49"
--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ VB > soccer