码迷,mamicode.com
首页 > 其他好文 > 详细

字符串输出

时间:2017-10-30 18:19:27      阅读:159      评论:0      收藏:0      [点我收藏+]

标签: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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!