标签:tle log mes ons get seek head file 标识符
utf-8 标识符 0xEF 0xBB 0xBF
CStdioFile file; if (file.Open(strConfigFileDir, CFile::modeReadWrite | CFile::modeNoTruncate | CFile::modeCreate)) { BYTE head[3]; CString strFile; file.Read(head, 3);//BOM头 EF BB BF file.ReadString(strFile); if (!(head[0] == 0xEF && head[1] == 0xBB && head[2] == 0xBF)) { file.SeekToBegin(); const unsigned char LeadBytes[] = { 0xEF, 0xBB, 0xBF }; file.Write(LeadBytes, sizeof(LeadBytes)); } }
Unicode 标识符:0XFEFF
file.WriteString(L"0XFEFF");
文件打开方式插入字符串:
if (file.Open(strConfigFileDir, CFile::modeRead)) { char chBuffer[512000] = { 0 }; unsigned int bufferSize = sizeof(chBuffer) / sizeof(char); long lFileSize = file.GetLength(); int times = lFileSize / bufferSize; if (lFileSize % bufferSize > 0) { times++; } for (int i = 0; i < times; i++) { file.Read(chBuffer, bufferSize); spstrText->Append(chBuffer); } unsigned long iEndPos = spstrText->Find("</Config>"); CStringA strOneRecord = spstrText->Mid(0, iEndPos); strOneRecord.Append(L"xxxxxxx"); } file.Close();
Unicode 转utf-8
CStringA utf8String(str); int nSrcLen = (int)wcslen(str); int nBufLen = (nSrcLen + 1) * 6; LPSTR buffer = utf8String.GetBufferSetLength(nBufLen); int nLen = AtlUnicodeToUTF8(str, nSrcLen, buffer, nBufLen); buffer[nLen] = 0; utf8String.ReleaseBuffer();
标签:tle log mes ons get seek head file 标识符
原文地址:http://www.cnblogs.com/ye-ming/p/7755323.html