MFC UNICODE項目CFILE寫html文件亂碼解決


 CFile file; CString filename = D:\\; filename+=L"index.html"; file.Open(filename,CFile::modeCreate|CFile::modeWrite); file.SeekToBegin(); WORD unicode = 0xFEFF; //UNICODE編碼文件頭 file.Write(&unicode,2); file.Write(CString內容,CString內容.GetLength()*2); file.Flush(); file.Close();

 

 

文本支持四種格式:ANSI/Unicode/Unicode big endian/UFT-8

不同編碼的文本,是根據文本的前兩個字節來定義其編碼格式的。定義如下:

ANSI: 無格式定義

Unicode: 前兩個字節為FFFE

Unicode big endian: 前兩字節為FEFF

UTF-8: 前兩字節為EFBBBF

arrow
arrow

    NoSleep 發表在 痞客邦 留言(0) 人氣()