Read the UTF-8 format text file remove the three bytes of the file header, first read the text data to the char array, then convert the multi-byte utf8 string into a wide character Unicode string, then convert the Unicode string to a char string or directly copy it to the cstring (both UTF-8 and char belong to multibyte char and cannot be directly converted to each other) bool readutf8stringfile (cstring path, cstring & Str) {cfile filer; If (! Filer. open (path, cfile: moderead | cfile: typebinary) {MessageBox (null, _ T ("file cannot be opened:") + path, _ T ("error"), mb_iconerror | mb_ OK); Return false;} byte head [3]; filer. read (Head, 3); If (! (Head [0] = 0xef & head [1] = 0xbb & head [2] = 0xbf) {filer. seektobegin ();} ulonglong filesize = filer. getlength (); char * Pcontent = (char *) calloc (filesize + 1, sizeof (char); filer. read (Pcontent, filesize); filer. close (); int n = multibytetowidechar (cp_utf8, 0, Pcontent, filesize + 1, null, 0); wchar_t * pwidechar = (wchar_t *) calloc (n + 1, sizeof (wchar_t); multibytetowidechar (cp_utf8, 0, Pcontent, filesize + 1, pwidechar, n); STR = cstring (pwidechar); free (Pcontent); free (pwidechar ); return true ;}