zoukankan      html  css  js  c++  java
  • 字符串输出

    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();
  • 相关阅读:
    博客园样式设置
    最坏情况为线性时间的选择算法
    棋盘覆盖
    矩阵乘法的Strassen算法及时间复杂度
    大整数乘法及算法时间复杂度
    全排列问题的递归算法(Perm)
    python的lambda
    python的zip函数
    python操作队列
    mysql基础命令
  • 原文地址:https://www.cnblogs.com/ye-ming/p/7755323.html
Copyright © 2011-2022 走看看