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