1.ANSI与Unicode
Unicode字符集中一个字符占两个字节,GB2312通常采用EUC储存方法,以便兼容于ASCII。每个汉字及符号以两个字节来表示。
2.
const int UNICODE_TXT_FLG = 0xFEFF;
//写入ANSCI
CString strPath;
strPath = L"D://ANSCI_Test.log";
CStringA strTmp;
strTmp = "测试字符集";
CFile fl1;
fl1.Open(strPath,CFile::modeCreate | CFile::modeReadWrite | CFile::modeNoTruncate);
int nLen = strTmp.GetLength(); // 10
fl1.Write(StrTmp,strTmp.GetLength());
fl1.Close();
//写入Unicode
strPath = L"D://Unicode_Test.log";
CFile fl2;
//1.TCHAR写入
TCHAR chinfo[] = L"测试字符集";
fl2.Open(strPath,CFile::modeCreate | CFile::modeReadWrite | CFile::modeNoTruncate);
int nchLen = = wcslen(chinfo); // 5
fl2.Write(UNICODE_TXT_FLG,2);//写入UNICODE头部
fl2.Write(chinfo,nchLen * sizeof(TCHAR));
//2.CString写入
CString strCString;
strCString = _T("CString类的Unicode字符集写入文件");
fl2.Write(strCString,strCString.GetLength() * sizeof(TCHAR));
fl2.Close();