| # Include <iostream> # Include <string> Using namespace STD; Static char convert (wchar_t N ); Static bool in (wchar_t start, wchar_t end, wchar_t Code ); Int main (INT argc, char * argv []) { String sChinese = "I love China"; // input string Char CHR [3]; Wchar_t WCHR = 0; Char * buff = new char [sChinese. Length ()/2]; Memset (buff, 0x00, sizeof (char) * sChinese. Length ()/2 + 1 ); For (INT I = 0, j = 0; I <(sChinese. Length ()/2); ++ I) { Memset (CHR, 0x00, sizeof (CHR )); CHR [0] = sChinese [J ++]; CHR [1] = sChinese [J ++]; CHR [2] = '\ 0 '; // Encode a single character, for example, 'I' = 0xced2 WCHR = 0; WCHR = (CHR [0] & 0xff) <8; WCHR | = (CHR [1] & 0xff ); Buff [I] = convert (WCHR ); } Cout <"Pin Yin = [" <buff <"]" <Endl; Return 0; } Char convert (wchar_t N) { If (in (0xb0a1, 0xb0c4, n) return 'a '; If (in (0xb0c5, 0xb2c0, n) return 'B '; If (in (0xb2c1, 0xb4ed, n) return 'C '; If (in (0xb4ee, 0xb6e9, n) return 'D '; If (in (0xb6ea, 0xb7a1, n) return 'E '; If (in (0xb7a2, 0xb8c0, n) return 'F '; If (in (0xb8c1, 0xb9fd, n) return 'G '; If (in (0xb9fe, 0xbbf6, n) return 'H '; If (in (0xbbf7, 0xbfa5, n) return 'J '; If (in (0xbfa6, 0xc0ab, n) return 'K '; If (in (0xc0ac, 0xc2e7, n) return 'l '; If (in (0xc2e8, 0xc4c2, n) return 'M '; If (in (0xc4c3, 0xc5b5, n) return 'n '; If (in (0xc5b6, 0xc5bd, n) return 'O '; If (in (0xc5be, 0xc6d9, n) return 'P '; If (in (0xc6da, 0xc8ba, n) return 'q '; If (in (0xc8bb, 0xc8f5, n) return 'R '; If (in (0xc8f6, 0xcbf0, n) Return's '; If (in (0 xcbfa, 0xcdd9, n) return 'T '; If (in (0 xcdda, 0xcef3, n) return 'W '; If (in (0xcef4, 0xd188, n) return 'X '; If (in (0xd1b9, 0xd4d0, n) return 'y '; If (in (0xd4d1, 0xd7f9, n) return 'Z '; Return '\ 0 '; } Bool in (wchar_t start, wchar_t end, wchar_t code) { If (code> = Start & Code <= end) { Return true; } Return false; } |