Example:
Int n_wchar_t = sizeof (wchar_t); // n_wchar_t = 2
Int n_char = sizeof (char); // n_char = 1
The preceding example shows that wchar_t and Char have different lengths.
Example:
Wchar_t * wch = l "abcdef ";
Int n_wch = wcslen (wch); // n_wch = 6
Char * Ch = "abcdef ";
Int n_ch = strlen (CH); // n_ch = 6
As shown in the preceding example, wcslen and strlen have the same functions. Others only have different prefixes and have the same functions.
Example:
Char * Ch = "abcdef ";
Wchar_t * wch;
Wch = (wchar_t *) ch;
Int n_ch = strlen (CH); // n_ch = 6
Int n_wch = wcslen (wch); // n_wch = 3
As shown in the preceding example, when the char pointer variable is forcibly converted to the wchar_t pointer variable, two characters in the memory unit pointed to by the char pointer will be treated as one character and unexpected results will appear, you can use breakpoints for debugging.
Example:
Char CH = 'C ';
Wchar_t wch;
Wch = CH; // wch = 'C'
The preceding example shows that there is no error when there is only one character.
Example of converting char * To wchar_t *
Char * src = "adscd ";
Int dest_len;
Int J = strlen (SRC); // J = 5
Dest_len = multibytetowidechar (cp_acp, 0, SRC,-1, null, 0); // get the length required for the conversion wchar_t * variable dest_len = 6
Wchar_t * DEST = new wchar_t [dest_len]; // DEST = l "adscd"
ID (DEST = NULL)
Return;
Int I = wcslen (DEST); // I = 5
If (DEST)
{
Delete [] DEST;
DeST = NULL;
}