将CStdioFile类扩展,读取UNICODE和ANSI文本文件

支持UNICODE读写的MFC扩展类 CStdioFileEx 支持UNICODE读写的MFC扩展类 CStdioFileEx ,读取文件的时候自动判断字符集,非常好用。附例子程序 立即下载

 

原文:http://dev.csdn.net/article/38/38303.shtm

在此基础上修改了部分代码。

 

最近因为要读取SQL脚本文件,用CStdioFile来读取脚本文件,却在程序调试时读取不了文件。
后来看了一下文本文件格式,竟然是UNICODE格式的,原来在导出SQL脚本的时候,选项默认的是UNICODE格式。为了同时支持ANSI和UNICODE两种格式,在Codeproject站点上找到了CStdioFileEx类的代码,但在调试运行过程中发现,在生成UNICODE版本的执行文件时,运行没有错误,但在非UNICODE版本中却出现错误,原来在代码中此部分没有考虑文件读到末尾的情况,经修改,CStdioFileEx类就可以正常使用了,在读取文本文件时,自动识别ANSI和UNICODE两种格式。
实现头文件如下:


#define nUNICODE_BOM      0xFEFF  // Unicode "byte order mark" which goes at start of file
#define sNEWLINE        _T("/r/n") // New line characters
#define sDEFAULT_UNICODE_FILLER_CHAR "#"   // Filler char used when no conversion from Unicode to local code page is possible

class CStdioFileEx: public CStdioFile
{
public:
 CStdioFileEx();
 CStdioFileEx( LPCTSTR lpszFileName, UINT nOpenFlags );

 virtual BOOL Open( LPCTSTR lpszFileName, UINT nOpenFlags, CFileException* pError = NULL );
 virtual BOOL ReadString(CString& rString);
 virtual void WriteString( LPCTSTR lpsz );
 bool    IsFileUnicodeText() { return m_bIsUnicodeText; } 
 unsigned long GetCharCount();

 // Additional flag to allow Unicode text writing
 static const UINT modeWriteUnicode;

 // static utility functions

 // --------------------------------------------------------------------------------------------
 //
 // CStdioFileEx::GetUnicodeStringFromMultiByteString()
 //
 // --------------------------------------------------------------------------------------------
 // Returns:    bool
 // Parameters: char *  szMultiByteString  (IN) Multi-byte input string
 //     wchar_t*  szUnicodeString  (OUT) Unicode output string
 //     short   nUnicodeBufferSize (IN) Size of Unicode output buffer
 //     UINT   nCodePage    (IN) Code page used to perform conversion
 //                  Default = -1 (Get local code page).
 //
 // Purpose:  Gets a Unicode string from a MultiByte string.
 // Notes:  None.
 // Exceptions: None.
 //
 static bool  GetUnicodeStringFromMultiByteString(char * szMultiByteString,wchar_t* szUnicodeString,
                   short nUnicodeBufferSize,UINT nCodePage=-1);

 // --------------------------------------------------------------------------------------------
 //
 // CStdioFileEx::GetMultiByteStringFromUnicodeString()
 //
 // --------------------------------------------------------------------------------------------
 // Returns:    BOOL
 // Parameters: wchar_t * szUnicodeString   (IN) Unicode input string
 //     char*   szMultiByteString   (OUT) Multibyte output string
 //     short   nMultiByteBufferSize  (IN) Multibyte buffer size
 //     UINT   nCodePage     (IN) Code page used to perform conversion
 //                   Default = -1 (Get local code page).
 //
 // Purpose:  Gets a MultiByte string from a Unicode string.
 // Notes:  .
 // Exceptions: None.
 //
 static BOOL   GetMultiByteStringFromUnicodeString(wchar_t * szUnicodeString,char* szMultiByteString,
                   short nMultiByteBufferSize,UINT nCodePage=-1);


 // --------------------------------------------------------------------------------------------
 //
 // CStdioFileEx::IsFileUnicode()
 //
 // --------------------------------------------------------------------------------------------
 // Returns:    bool
 // Parameters: const CString& sFilePath
 //
 // Purpose:  Determines whether a file is Unicode by reading the first character and detecting
 //     whether it's the Unicode byte marker.
 // Notes:  None.
 // Exceptions: None.
 //
 static bool IsFileUnicode(const CString& sFilePath);


protected:
 UINT ProcessFlags(const CString& sFilePath, UINT& nOpenFlags);

 bool  m_bIsUnicodeText;
 UINT  m_nFlags;
};

 

实现文件如下:


/*static*/ const UINT CStdioFileEx::modeWriteUnicode = 0x20000; // Add this flag to write in Unicode

CStdioFileEx::CStdioFileEx(): CStdioFile()
{
 m_bIsUnicodeText = false;
}

CStdioFileEx::CStdioFileEx(LPCTSTR lpszFileName,UINT nOpenFlags)
 :CStdioFile(lpszFileName, ProcessFlags(lpszFileName, nOpenFlags))
{
}

BOOL CStdioFileEx::Open(LPCTSTR lpszFileName,UINT nOpenFlags,CFileException* pError /*=NULL*/)
{
 // Process any Unicode stuff
 ProcessFlags(lpszFileName, nOpenFlags);

 return CStdioFile::Open(lpszFileName, nOpenFlags, pError);
}

BOOL CStdioFileEx::ReadString(CString& rString)
{
 const int nMAX_LINE_CHARS = 4096;
 BOOL   bReadData;
 LPTSTR  lpsz;
 int   nLen = 0; //, nMultiByteBufferLength = 0, nChars = 0;
 CString  sTemp;
 wchar_t*  pszUnicodeString = NULL;
 char *  pszMultiByteString= NULL;

 // If at position 0, discard byte-order mark before reading
 if (!m_pStream || (GetPosition() == 0 && m_bIsUnicodeText))
 {
  wchar_t cDummy;
//  Read(&cDummy, sizeof(_TCHAR));
  Read(&cDummy, sizeof(wchar_t));
 }

// If compiled for Unicode
#ifdef _UNICODE
 // Do standard stuff -- both ANSI and Unicode cases seem to work OK

if(m_bIsUnicodeText)

{
  bReadData = CStdioFile::ReadString(rString);

}

else

{

  pszUnicodeString = new wchar_t[nMAX_LINE_CHAR];

    pszMultiByteString = new wchar_t[nMAX_LINE_CHAR];

 

    //read as ansi

   if(fgets(pszMultiByteString,nMAX_LINE_CHAR,m_pStream) == NULL)

  {

      bReadData = false;

   }

   else

   {

      bReadData = true;

      if(GetUnicodeStringFromMultiByteString(pszMultiByteString,pszUnicodeString,nMAX_LINE_CHAR,GetACP()))

      {

          rString = (CString)pszUnicodeString;

       }

     

       if(pszUnicodeString)

       {

           delete [] pszUnicodeString;

        }

 

       if(pszMultiByteString)

       {

          delete [] pszMultiByteString;

        }

 

 

 

 

   }

}
#else

 if (!m_bIsUnicodeText)
 {
  // Do standard stuff -- read ANSI in ANSI
  bReadData = CStdioFile::ReadString(rString);
 }
 else
 {
  pszUnicodeString = new wchar_t[nMAX_LINE_CHARS];
  pszMultiByteString= new char[nMAX_LINE_CHARS]; 

  // Read as Unicode, convert to ANSI

  if(fgetws(pszUnicodeString, nMAX_LINE_CHARS, m_pStream)==NULL)
  {  
   bReadData=FALSE;
  }
  else
  {
   bReadData=TRUE;
   if (GetMultiByteStringFromUnicodeString(pszUnicodeString, pszMultiByteString, nMAX_LINE_CHARS))
   {
    rString = (CString)pszMultiByteString;
   }

   if (pszUnicodeString)
   {
    delete pszUnicodeString;
   }

   if (pszMultiByteString)
   {
    delete pszMultiByteString;
   }
  }
 }
#endif

 // Then remove end-of-line character if in Unicode text mode
 if (bReadData)
 {
  // Copied from FileTxt.cpp but adapted to Unicode and then adapted for end-of-line being just '/r'.
  nLen = rString.GetLength();
  if (nLen > 1 && rString.Mid(nLen-2) == sNEWLINE)
  {
   rString.GetBufferSetLength(nLen-2);
  }
  else
  {
   lpsz = rString.GetBuffer(0);
   if (nLen != 0 && (lpsz[nLen-1] == _T('/r') || lpsz[nLen-1] == _T('/n')))
   {
    rString.GetBufferSetLength(nLen-1);
   }
  }
 }

 return bReadData;
}

// --------------------------------------------------------------------------------------------
//
// CStdioFileEx::WriteString()
//
// --------------------------------------------------------------------------------------------
// Returns:    void
// Parameters: LPCTSTR lpsz
//
// Purpose:  Writes string to file either in Unicode or multibyte, depending on whether the caller specified the
//     CStdioFileEx::modeWriteUnicode flag. Override of base class function.
// Notes:  If writing in Unicode we need to:
//      a) Write the Byte-order-mark at the beginning of the file
//      b) Write all strings in byte-mode
//     - If we were compiled in Unicode, we need to convert Unicode to multibyte if
//      we want to write in multibyte
//     - If we were compiled in multi-byte, we need to convert multibyte to Unicode if
//      we want to write in Unicode.
// Exceptions: None.
//
void CStdioFileEx::WriteString(LPCTSTR lpsz)
{
 // If writing Unicode and at the start of the file, need to write byte mark
 if (m_nFlags & CStdioFileEx::modeWriteUnicode)
 {
  // If at position 0, write byte-order mark before writing anything else
  if (!m_pStream || GetPosition() == 0)
  {
   wchar_t cBOM = (wchar_t)nUNICODE_BOM;
   CFile::Write(&cBOM, sizeof(wchar_t));
  }
 }

// If compiled in Unicode...
#ifdef _UNICODE

 // If writing Unicode, no conversion needed
 if (m_nFlags & CStdioFileEx::modeWriteUnicode)
 {
  // Write in byte mode
  CFile::Write(lpsz, lstrlen(lpsz) * sizeof(wchar_t));
 }
 // Else if we don't want to write Unicode, need to convert
 else
 {
  int  nChars = lstrlen(lpsz) + 1;    // Why plus 1? Because yes
  int  nBufferSize = nChars * sizeof(char);
  wchar_t* pszUnicodeString = new wchar_t[nChars];
  char * pszMultiByteString= new char[nChars]; 

  // Copy string to Unicode buffer
  lstrcpy(pszUnicodeString, lpsz);

  // Get multibyte string
  if (GetMultiByteStringFromUnicodeString(pszUnicodeString, pszMultiByteString, nBufferSize, GetACP()))
  {
   // Do standard write
   CFile::Write((const void*)pszMultiByteString, lstrlen(lpsz));
  }

  if (pszUnicodeString && pszMultiByteString)
  {
   delete [] pszUnicodeString;
   delete [] pszMultiByteString;
  }
 }
// Else if *not* compiled in Unicode
#else
 // If writing Unicode, need to convert
 if (m_nFlags & CStdioFileEx::modeWriteUnicode)
 {
  int  nChars = lstrlen(lpsz) + 1;  // Why plus 1? Because yes
  int  nBufferSize = nChars * sizeof(wchar_t);
  wchar_t* pszUnicodeString = new wchar_t[nChars];
  char * pszMultiByteString= new char[nChars];

  // Copy string to multibyte buffer
  lstrcpy(pszMultiByteString, lpsz);

  if (GetUnicodeStringFromMultiByteString(pszMultiByteString, pszUnicodeString, nBufferSize, GetACP()))
  {
   // Write in byte mode
   CFile::Write(pszUnicodeString, lstrlen(lpsz) * sizeof(wchar_t));
  }
  else
  {
   ASSERT(false);
  }

  if (pszUnicodeString && pszMultiByteString)
  {
   delete [] pszUnicodeString;
   delete [] pszMultiByteString;
  }
 }
 // Else if we don't want to write Unicode, no conversion needed
 else
 {
  // Do standard stuff
  CStdioFile::WriteString(lpsz);
 }

#endif
}

UINT CStdioFileEx::ProcessFlags(const CString& sFilePath, UINT& nOpenFlags)
{
 m_bIsUnicodeText = false;

 // If we have writeUnicode we must have write or writeRead as well
#ifdef _DEBUG
 if (nOpenFlags & CStdioFileEx::modeWriteUnicode)
 {
  ASSERT(nOpenFlags & CFile::modeWrite || nOpenFlags & CFile::modeReadWrite);
 }
#endif

 // If reading in text mode and not creating...
 if (nOpenFlags & CFile::typeText && !(m_nFlags & CFile::modeCreate) && !(m_nFlags & CFile::modeWrite ))
 {
  m_bIsUnicodeText = IsFileUnicode(sFilePath);

  // If it's Unicode, switch to binary mode
  if (m_bIsUnicodeText)
  {
   nOpenFlags ^= CFile::typeText;
   nOpenFlags |= CFile::typeBinary;
  }
 }

 m_nFlags = nOpenFlags;

 return nOpenFlags;
}

// --------------------------------------------------------------------------------------------
//
// CStdioFileEx::IsFileUnicode()
//
// --------------------------------------------------------------------------------------------
// Returns:    bool
// Parameters: const CString& sFilePath
//
// Purpose:  Determines whether a file is Unicode by reading the first character and detecting
//     whether it's the Unicode byte marker.
// Notes:  None.
// Exceptions: None.
//
/*static*/ bool CStdioFileEx::IsFileUnicode(const CString& sFilePath)
{
 CFile    file;
 bool    bIsUnicode = false;
 wchar_t   cFirstChar;
 CFileException exFile;

 // Open file in binary mode and read first character
 if (file.Open(sFilePath, CFile::typeBinary | CFile::modeRead, &exFile))
 {
  // If byte is Unicode byte-order marker, let's say it's Unicode
  if (file.Read(&cFirstChar, sizeof(wchar_t)) > 0 && cFirstChar == (wchar_t)nUNICODE_BOM)
  {
   bIsUnicode = true;
  }

  file.Close();
 }
 else
 {
  // Handle error here if you like
 }

 return bIsUnicode;
}

unsigned long CStdioFileEx::GetCharCount()
{
 int    nCharSize;
 unsigned long nByteCount, nCharCount = 0;

 if (m_pStream)
 {
  // Get size of chars in file
  nCharSize = m_bIsUnicodeText ? sizeof(wchar_t): sizeof(char);

  // If Unicode, remove byte order mark from count
  nByteCount = (unsigned long)GetLength();
  
  if (m_bIsUnicodeText)
  {
   nByteCount = nByteCount - sizeof(wchar_t);
  }

  // Calc chars
  nCharCount = (nByteCount / nCharSize);
 }

 return nCharCount;
}

// --------------------------------------------------------------------------------------------
//
// CStdioFileEx::GetUnicodeStringFromMultiByteString()
//
// --------------------------------------------------------------------------------------------
// Returns:    bool
// Parameters: char *  szMultiByteString  (IN) Multi-byte input string
//     wchar_t*  szUnicodeString  (OUT) Unicode outputstring
//     short   nUnicodeBufferSize (IN) Size of Unicode output buffer
//     UINT   nCodePage    (IN) Code page used to perform conversion
//                  Default = -1 (Get local code page).
//
// Purpose:  Gets a Unicode string from a MultiByte string.
// Notes:  None.
// Exceptions: None.
//
bool CStdioFileEx::GetUnicodeStringFromMultiByteString(char * szMultiByteString, wchar_t* szUnicodeString, short nUnicodeBufferSize, UINT nCodePage)
{
 bool  bOK = true;
 int  nReturn = 0;
 CString sErrorMsg;
  
 if (szUnicodeString && szMultiByteString)
 {
  // If no code page specified, take default for system
  if (nCodePage == -1)
  {
   nCodePage = GetACP();
  }

  try
  {
   nReturn = MultiByteToWideChar(nCodePage,MB_PRECOMPOSED,szMultiByteString,-1,szUnicodeString,nUnicodeBufferSize);

   if (nReturn == 0)
   {
    bOK = false;
   }
  }
  catch(...)
  {
   bOK = false;
  }
 }
 else
 {
  bOK = false;
 }

 ASSERT(bOK);
 return bOK;
}

// --------------------------------------------------------------------------------------------
//
// CStdioFileEx::GetMultiByteStringFromUnicodeString()
//
// --------------------------------------------------------------------------------------------
// Returns:    BOOL
// Parameters: wchar_t * szUnicodeString   (IN) Unicode input string
//     char*   szMultiByteString   (OUT) Multibyte output string
//     short   nMultiByteBufferSize  (IN) Multibyte buffer size
//     UINT   nCodePage     (IN) Code page used to perform conversion
//                   Default = -1 (Get local code page).
//
// Purpose:  Gets a MultiByte string from a Unicode string
// Notes:  None.
// Exceptions: None.
//
BOOL CStdioFileEx::GetMultiByteStringFromUnicodeString(wchar_t * szUnicodeString, char* szMultiByteString,
                   short nMultiByteBufferSize, UINT nCodePage)
{
 BOOL   bUsedDefChar = FALSE;
 BOOL   bGotIt = FALSE;

 if (szUnicodeString && szMultiByteString)
 {
  // If no code page specified, take default for system
  if (nCodePage == -1)
  {
   nCodePage = GetACP();
  }

  try
  {
   bGotIt = WideCharToMultiByte(nCodePage, WC_COMPOSITECHECK | WC_SEPCHARS,
       szUnicodeString,-1, szMultiByteString, nMultiByteBufferSize, sDEFAULT_UNICODE_FILLER_CHAR, &bUsedDefChar);
  }
  catch(...)
  {
   TRACE(_T("Controlled exception in WideCharToMultiByte!/n"));
  }
 }

 return bGotIt;
}

CStdioFileEx(支持ANSI、UNICODE、UNICODE big endian、UTF-8编码的文本读取 /*程序用途:按行读取常见 (包括ANSI、UNICODE、UNICODE big endian、UTF-8)格式的文本文件 */ //核心算法:CStdioFileEx继承自CStdioFile, 覆盖CStdioFile的 BOOL ReadString(CString& rString)方法, // 根据不同文件编码特征,寻找文件回车换行符判断读取行结束,文件结束符判断文件结束 // 检测不同文件编码头部,获取文件类型后调用不同的读取函数 //测试结果:在Windows7 VS2008环境下测试上述四种格式的txt文件通过 //尚未完成:未重载CStdioFile的 virtual LPTSTR ReadString( LPTSTR lpsz, UINT nMax )方法 // 未完成WriteString方法,未在VC UNICODE 环境下的测试 立即下载

相关推荐

支持UNICODE读写的MFC扩展类 CStdioFileEx 的例子

支持UNICODE读写的MFC扩展类 CStdioFileEx 的例子

【CStdioFile扩展(支持Ansi、Unicode、Utf-8等文本格式)】

例如:以下是官方博客例子浅析先加入相关的头文件和库文件。提示:以下是本篇文章正文内容,下面案例可供参考提示:这里对文章进行总结:例如:以上就是今天要讲的内容,本文仅仅简单介绍了的函数和方法。

我的博客 1036

注册表文件(reg)转换成安装文件(inf)

通过将reg文件转换成inf文件,这样就可以使用RUNDLL32.EXE SETUPAPI.DLL,InstallHinfSection DefaultInstall 128 .\xxx.inf进行绿色软件的注册表注册了。

CStdioFileEx

<br />class CStdioFileEx : public CStdioFile<br />{<br />public:<br /> BOOL Open(LPCTSTR lpszFileName, UINT nOpenFlags, CFileException* pError  = NULL )<br /> {<br />  if(CStdioFile::Open(lpszFileName,nOpenFlags,pError))<br />  {<br />   BYTE head[3];<br /

gpr1983的专栏 851

单细胞数据互转实战:从Scanpy的h5ad到Seurat对象的四种高效方法

本文针对单细胞数据分析中Scanpy的h5ad格式与Seurat对象互转的常见难题,详细对比了SeuratDisk、anndataR、schard和sceasy四种高效转换方法。文章从实战出发,剖析了每种方法的原理、操作流程、优缺点及避坑指南,并提供了清晰的选型策略,帮助用户根据数据特点选择最佳方案,实现跨平台数据的无缝衔接。

weixin_29099217的博客 458

2019年上交电院计算机直博保研经历

本人选报的是上交六月一日在武汉举办的直博选拔,五月三十一日到达酒店,地点在武汉大学旁边(PS:上交是不管住宿、来回车票的,~划重点~包括夏令营),入住后当然是紧张的准备英语面试等等内容了,当天我是排在了下午面试,感觉还很好,上午可以多睡一会,最好能够去踩踩点上午,然后下午面试一定要早去,说是一点开始,但是老师十二点半就开始让学生进去了,有一个同学排在第二个,但是当时叫到他时还不到一点,没到,最后据...

LifeMaker的博客 4908

VC 编程ANSI环境下读写Unicode文件和将CStdioFile类扩展,读取UNICODE文本文件

VC 编程ANSI环境下读写Unicode文件没有注意到文件编码的不同会产生这么多的问题,在动手以前查询了很多资料,在本博客中收藏了不少先辈的成果,在这里一并表示致敬!       关于ANSI和Unicode编码的原理在这里也不说了,主要讲下如何读写!       首先确定你的工程是采用的是什么编码环境,默认是ANSI,不同的字符集读写文件的差别也比较大,我这里只在ANSI环境下做的,下一步在探

阳光岛主 7658

告别瞎猜!用通达信L2资金流向函数,手把手教你识别主力动向(附实战公式)

本文详细解析通达信L2资金流向函数,手把手教你构建主力动向监控系统。通过分档数据解析、委买委卖攻防解读及实战公式应用,帮助投资者精准识别主力建仓与虚假拉升信号,提升股票交易决策效率。

weixin_26908317的博客 2177

VC ANSI环境下按行读取ANSI、UNICODE 、UNICODE big endian、UTF-8四种文本文件

VC ANSI环境下按行读取ANSI、UNICODE 、UNICODE big endian、UTF-8四种文本文件 1.问题提出 MFC提供的文件类CStdioFile,其中一个函数ReadString实现了文件的按行读取,但是不能满足不同类型的文本文件的按行读取,为了解决这一问题,笔者初步研究了一些编码知识,参考了网上的一些资料,实现了CStdioFile类的扩展类CStdioFile

王定桥的专栏 8817

S7-1200控制S120变频器

②:硬件目录下,添加实物S120设备进行组态(其它现场设备--PROFINET IO--DRIVES......②:双击S120进行IP地址和设备名称设置(注:此处要与STATER软件设置S120一致)M10.0接通时,电机开始运行,M10.0断开,电机停止,调试完成。①:将S7-1200与S120进行通讯连线。④:STATER软件下设置与组态一致的报文。①:点击添加新设备,按实物进行设备组态。②:打开OB1,编写启动停止程序。①:查看S120报文地址。②:模块下添加DO矢量。③:子模块下添加报文。

weixin_38261173的博客 4874

9、储备池学习:从学习到学习的新范式

本文探讨了基于学习到学习(L2L)框架的储备池计算新范式,提出通过在外循环中优化储备池的超参数(如递归连接权重、输入权重和读出初始化),以提升其在多种任务中的内循环学习性能。研究展示了两种主要实验设置:一是优化储备池用于回归二阶Volterra滤波器任务,显著优于随机基线;二是实现无需调整读出权重、仅依赖内部动态学习非线性函数的能力,表明储备池可快速构建目标函数的内部模型并安装任务先验知识。结合流程图与表格,文章系统呈现了L2L的训练流程、技术细节及实验结果,并讨论了性能提升、泛化能力等开放问题,指出了未来

ujm56789012的博客 513

将CStdioFile类扩展,读取UNICODE文本文件

最近因为要读取SQL脚本文件,用CStdioFile来读取脚本文件,却在程序调试时读取不了文件。后来看了一下文本文件格式,竟然是UNICODE格式的,原来在导出SQL脚本的时候,选项默认的是UNICODE格式。为了同时支持ANSI和UNICODE两种格式,在Codeproject站点上...

chenqunan3231的博客 189

手把手教你学Simulink——机器人控制场景实例:基于Simulink的双足人形机器人步态生成与ZMP稳定控制仿真

ZMP是地面上合力矩在水平方向为零的点。对于平面行走: [ x_{\text{zmp}} = x_c - \frac{z_c}{g} \ddot{x}_c ]📌稳定性判据ZMP必须始终位于支撑脚的凸包(即脚掌范围内)本文完成了基于Simulink的双足人形机器人ZMP稳定控制仿真,实现了:✅ 基于LIPM生成稳定CoM轨迹✅ 构建ZMP参考与验证机制✅ 设计简化踝关节PD控制器✅ 验证ZMP始终位于支撑脚内 → 动态平衡✅ 为人形机器人步态规划奠定理论基础。

MHD0815的博客 142

按行读取ANSI、UNICODE 、UNICODE big endian、UTF-8四种文本文

代码简介 1.问题提出 MFC提供的文件类CStdioFile,其中一个函数ReadString实现了文件的按行读取,但是不能满足不同类型的文本文件的按行读取,为了解决这一问题,笔者初步研究了一些编码知识,参考了网上的一些资料,实现了CStdioFile类的扩展类CStdioFileEx,完成了常见文本文件的按行读取(注明:不包括DOC、PDF等其他形式的文档). 在此对网上分享编码经验的网

sky101010ws的专栏 4241

Cesium 相机操作

Cesium 提供了三种方式对相机的位置进行摆放。

虎康的博客 2599

YOLOv11知识蒸馏实战:让小模型拥有大模型90%精度,速度提升3倍的终极教程

在self.alpha = alpha # 蒸馏损失权重self.temperature = temperature # 温度系数,控制分布平滑度# 输出分布蒸馏(KL散度损失)# 中间特征蒸馏(MSE损失,对齐中间层特征)# 总蒸馏损失知识蒸馏是YOLOv11在“小模型高性能部署”场景的“破局之法”——它让小模型能“站在大模型的肩膀上”,兼具速度与精度。从损失函数定义到多阶段训练,再到实战落地,本教程已为你铺就了一条清晰的路径。

m0_64661770的博客 804

CStdioFileEx读取Unicode文本

 最近因为要读取SQL脚本文件,用CStdioFile来读取脚本文件,却在程序调试时读取不了文件。后来看了一下文本文件格式,竟然是UNICODE格式的,原来在导出SQL脚本的时候,选项默认的是UNICODE格式。为了同时支持ANSI和UNICODE两种格式,在Codeproject站点上找到了CStdioFileEx类的代码,但在调试运行过程中发现,在生成UNICODE版本的执行文件时,运行没

学无紫晶 4862

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

上一篇: Windows内核调试器原理浅析
下一篇: 生成Unicode版本的Ini文件
less@more
博客等级 码龄21年 181粉丝 162原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值