UTF-8 to ACSII conversion (let your C ++ program support multilingual)

xiaoxiao2021-03-06  76

My idea is this: UTF-8 encoding in the profile (basically using XML format), so any text in the world can be displayed. But if you read the configuration content directly, it is definitely garbled in your C program, so how to solve it? The steps are as follows (directly to the code)

Char szutf8 [] = {0xE4, 0XBB, 0XB7, 0XE5, 0X80, 0XBC}; // is the value of Chinese

INT Nlen = MultibyTetowideChar (CP_UTF8, 0, SZUTF8, -1, NULL, NULL); // Get UTF8 encoded strings length, 2

LPWSTR LPWSZ = New Wchar [NLEN];

MultibyToWideChar (CP_UTF8, 0, SZUTF8, -1, LPWSZ, NLEN); // The result of the conversion is two words in the UCS2 format.

INT NLEN1 = Widechartomultibyte (CP_ACP, 0, LPWSZ, NLEN, NULL, NULL, NULL, NULL);

LPSTR LPSZ = New Char [Nlen1];

WideChartomultibyte (CP_ACP, 0, LPWSZ, NLEN, LPSZ, NLEN1, NULL, NULL); // The conversion is completed, getting the "value" of the "value" on my machine, the binary code 0xBC 0xDB 0xD6 0xB5

delete [] lpwsz; delete [] lps;

Subsequently, I tested Russian, Spanish, Japanese, Traditional Chinese, etc., can be displayed normally.

But it seems that there are some blame characters that cannot be displayed, I don't know what these characters are character set. Through understanding of the above knowledge, it should be easy to join multiple languages ​​in the C program.

转载请注明原文地址:https://www.9cbs.com/read-93606.html

New Post(0)