Asc
7-bit represents a character, all 0 to 11 total 128 characters, to use enough in English
A address ~65
A address ~97
0 Address ~48
Ascii
8-bit represents one character, 256 characters in total
codepage--code page, depending on the code page, 128 characters that become different countries
The difference between DBCS and Unicode encoding
DBCS character encoding:
There is a flaw in single-byte mixed-encoding e.g.
A I'm a programmer.
0203 0405 0607 0809 0a0b
However, when parsing, it is possible to:
02030405060708090a0b
0102 030405060708090a0b
Unicode
Both Chinese and English characters use a two-byte high-level complement of 0
A I'm a programmer.
0001 0203 0406 0607 0809 0a0b
Address the inherent deficiencies of DBCS coding
Application of Character Set
Char takes 1 bytes or 2 bytes per character (DBCS encoding mode)
Wide own character
wchar_t 2 bytes per character (UNICODE)
wchar_t is actually the unsigned short type, when defined, you need to add "L" to inform the compiler to follow a double-byte compilation string, using Unicode encoding
You need to manipulate a wide-byte string using the support wchar_t function. For example:
wchar_t* pwsztest = L "Hello wchar";
Wprint (L "%s\n", pwsztest);
L is for the compiler to see Cl.exe, the compiler saw "" before I knew each character accounted for double-byte
//WinCharacter.cpp:Defines the entry point for the console application.//#include"stdafx.h"#include"stdio.h"#include"windows.h"#defineWidecharvoidC_char () {Char*psztext ="Hello Char"; printf ("%s\n", PszText);}voidW_char () {wchar_t*pwsztext= L"Hello WChar"; intNlen =wcslen (Pwsztext); wprintf (L"%s,%d\n", Pwsztext,nlen);//l only works on%s}voidT_char () {#ifdef Widechar//#ifndef This document to the original source of thewchar_t *psztext = L"Hello"; wprintf (L"%s\n", pszText);#else Char*psztext="Hello"; printf ("Single:%s\n", pszText);#endif}intMainintargcChar*argv[]) { //C_char (); //W_char ();T_char (); return 0;}
wprintf support for Unicode is not good, you can use Writeconsole instead
BOOL writeconsole (HANDLE hconsoleoutput,//Standard output handle standard input handle standard error handle In addition to these three classes other handles are temporarily understood to be used to find memory Constvoid* lpbuffer,//Output Content BufferDWORD Nnumberofcharstowrite,//prepare the length of the output contentLpdword Lpnumberofcharswritten,//length of actual output contentLPVOID lpreserved//Spare); Getstdhandlehandle GetStdHandle (DWORD nstdhandle//Std_input_handle,std_output_handle,std_error_handle);//The return of the function gets the specific standard handle
//WinCharacter.cpp:Defines the entry point for the console application.//#include"stdafx.h"#include"stdio.h"#include"windows.h"#defineWidechar#defineUnicodevoidC_char () {Char*psztext ="Hello Char"; printf ("%s\n", PszText);}voidW_char () {wchar_t*pwsztext= L"Hello WChar"; intNlen =wcslen (Pwsztext); wprintf (L"%s,%d\n", Pwsztext,nlen);//l only works on%s}voidT_char () {TCHAR*psztest = __text ("Hello"); #ifdef UNICODE wprintf (L"%s\n", psztest);#elseprintf ("Single:%s\n", psztest);#endif/*#ifdef Widechar//#ifndef This document to the original source of wchar_t *psztext = L "Hello"; wprintf (L "%s\n", PszText); #else char *psztext= "Hello"; printf ("Single:%s\n", pszText); #endif*/}voidPrintfunicode () {HANDLE houtput=GetStdHandle (Std_output_handle); for(WORD Nhigh = -; nhigh< the; nhigh++) { for(WORD nlow= -; nlow< the; nlow++) {wchar_t Wcchar= nhigh* the+Nlow; //wprintf (L "%s", &wcchar);Writeconsole (Houtput,&wcchar,1, Null,null); } printf ("\ n"); }}intMainintargcChar*argv[]) { //C_char (); //W_char (); //T_char ();Printfunicode (); return 0;}
Windows core Programming 04-character encoding