文章分类 | 推荐文章 | 最新文章 | 热点文章 | 最新软件 | 精品软件 | 下载排行 | 推荐下载 | 免费看大片 | WPS | 杀毒软件
清风网络
首 页 软件下载 网络学院 数码学院
QQ 电脑入门 游戏 操作系统 图形处理 办公软件 媒体动画 精文荟萃 工具软件 网络编程 程序开发 网络技术 认证考试 网站建设 文章专栏
当前位置:清风网络学院程序开发IT人生将CStdioFile类扩展,读取UNICODE文本文件
精品推荐
特别推荐
·值得回忆的本科四年学习(1-6)
·如何检测内存泄漏——重载new和delete
·Linux IPC小结
·编程初学者的良言警句
·如何用正确的方法写出高质量软件的75条体会
·一个程序员的经典自白
·程序员十大安全技巧
热点TOP10
·七年之后我逃离编程
·从与客户沟通谈程序员的内在职业素养
·中国程序员何时走出大师崇拜阴影?
·微软原来有三个CTO 承诺未来五年再培养一万专业骨干软件人才
·编程初学者的良言警句
·dotproject 安装总结
·MATLAB对高等数学学习的有益帮助
·Spring之父Rod Johnson
·不朽的传奇——苹果演义
·Pascal之父:尼克劳斯·沃思

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

日期:2008年2月11日 作者: 查看:[大字体 中字体 小字体]


 //
 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
 bReadData = CStdioFile::ReadString(rString);
#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))

上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] 下一页 




上一篇:Flash V2组件初探

下一篇:通过middlebox实施P2P通讯三[传]

相关文章:
·dll文件下载
·局域网文件共享详解
·利用word将PDF转换DOC文件的方法
·java做的比较完善的FTP连接上传下载文件
·MPEG、RM、WMV电影文件格式转换指南
·从视频文件中提取声音的方法
·Coreldraw图像文件导入PS三种方法
·邮箱能否传输影音文件
·如何打开下载文件 文件后缀名大全
·C++中的文件输入/输出(4):检测输入/输出的状态标志
相关软件:
·最强文件加密锁2007
·Ultra RM Converter(Real文件转换分割,合并)V3.3.0916 汉化版
·西门子plc软件及教程 文件类型 其它介绍
·文件夹加密器V9.6
·常见多音多义字100个文本
·走遍美国 视频+文本 学习英语的绝好资料
·文件夹隐藏大师V3.2
·csf文件播放器 V5.0.0 1118
·2005监理执业考试文件汇编
·四级考试词频与四级语法文件

特别声明:本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。
[打印本页] [关闭窗口] 转载请注明来源:http://www.viphot.com
| 帮助(?) | 版权声明 | 友情连接 | 关于我们 | 信息发布
Copyright 2007 www.viphot.com All Rights Reserved. 鄂ICP备05000083号Powered by:viphot