wchar_t* U8tounicode (Char*szU8) { //UTF8 to Unicode//because the Chinese direct copy will be garbled, the compiler will sometimes error, so the use of 16 binary form//char* szU8 = "abcd1234\xe4\xbd\xa0\xe6\x88\x91\xe4\xbb\x96\x00"; //pre-conversion to get the size of the required space intWcsLen =:: MultiByteToWideChar (Cp_utf8, NULL, SzU8, strlen (szU8), NULL,0); //allocate space to ' MultiByteToWideChar ' to leave a space, will not give the ' \ ' spacewchar_t* wszstring =NewWchar_t[wcslen +1]; //Conversion:: MultiByteToWideChar (Cp_utf8, NULL, SzU8, strlen (szU8), wszstring, WcsLen); //finally add 'Wszstring[wcslen] =' /'; returnwszstring;}Char* UNICODETOU8 (wchar_t*Szunicode) { //Unicode to UTF8//wchar_t* wszstring = l "abcd1234 you and Me"; //pre-conversion, to get the size of the space required, this time the function with the above name opposite intU8len =:: WideCharToMultiByte (Cp_utf8, NULL, Szunicode, Wcslen (Szunicode), NULL,0, NULL, NULL); //as above, allocate space to ' \ ' to leave a space//Although UTF8 is a Unicode form of compression, it is also a multibyte string, so it can be saved as Char Char* SzU8 =New Char[U8len +1]; //Conversion//the corresponding strlen for the Unicode version is Wcslen:: WideCharToMultiByte (Cp_utf8, NULL, Szunicode, Wcslen (Szunicode), szU8, u8len, NULL, NULL); //finally add 'Szu8[u8len] =' /'; returnszU8;}Char* Unicodetoansi (wchar_t*Szunicode) { //Unicode to ANSI//wchar_t* wszstring = l "abcd1234 you and Me"; //pre-conversion, to get the size of the space required, this time the function with the above name opposite intAnsilen =:: WideCharToMultiByte (CP_ACP, NULL, Szunicode, Wcslen (Szunicode), NULL,0, NULL, NULL); //as above, allocate space to ' \ ' to leave a space Char* Szansi =New Char[Ansilen +1]; //Conversion//the corresponding strlen for the Unicode version is Wcslen:: WideCharToMultiByte (CP_ACP, NULL, Szunicode, Wcslen (Szunicode), Szansi, ansilen, NULL, NULL); //finally add 'Szansi[ansilen] =' /'; returnSzansi;} wchar_t* Ansitounicode (Char*Szansi) { //ANSI to Unicode//char* szansi = "abcd1234 you i he"; //pre-conversion to get the size of the required space intWcsLen =:: MultiByteToWideChar (CP_ACP, NULL, Szansi, strlen (Szansi), NULL,0); //allocate space to ' MultiByteToWideChar ' to leave a space, will not give the ' \ ' spacewchar_t* wszstring =NewWchar_t[wcslen +1]; //Conversion:: MultiByteToWideChar (CP_ACP, NULL, Szansi, strlen (Szansi), wszstring, WcsLen); //finally add 'Wszstring[wcslen] =' /'; returnwszstring;}
C + + character transcoding