本站启用国内永久域名: www.LewenSky.cn,请大家使用新域名访问网站!
8月19

MFC 文本文件的简单操作

| |
16:32MFC/VC++  From: 本站原创

CFile的派生类CStdioFile提供了对文件进行流式的操作功能。其中函数void CStdioFile::WriteString( LPCTSTR lpsz )写入一个字符串,需要给字符串lpsz的末尾加上换行标志”\r\n”;函数bool CStdioFile::ReadString(CString &rString )从文件中读取一行,如果文件未读完返回true,否则返回false。
比如:写入文件的例子

//创建文件


CStdioFile file;
/>file.Open("ts.txt",CFile::modeCreate|CFile::modeWrite);

//写入文件

CString str;
str.Format("%s\r\n","hello!I am talkingmute!");
file.Seek(0,CFile::end);
file.WriteString( str );

//关闭文件

file.Close();

比如:读文件的例子

CString strText = “”;
CString szLine = “”;

//打开文件
CStdioFile file;
file.Open("ts.txt",CFile::modeRead);

//逐行读取字符串
while( file.ReadString( szLine ) )
{
strText += szLine;
}

MessageBox(strText);

//关闭文件

file.Close();



作者:Lewen@博雅宇轩
地址:http://www.lewensky.cn/read.php/90.htm
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!


最新日志 随机日志 综合排行
  • OFFICE 2010 VOL...
  • 格式工厂绿色版 V2.90
  • Password Invent...
  • VideoCacheView ...
  • 电脑店U盘启动盘制作工具 3....
  • 阿里旺旺AliIM2011_7...
  • 极点五笔十周年纪念版
  • PPTV网络电视3.1.1.0...
  • WinRAR注册方法
  • 紫光华宇拼音输入法 6.8.0...
  • Photoshop蒙版妙用:无...
  • PPTV网络电视 2.6.3....
  • 暴风影音2012_3.10.1...
  • 雪豹主题Snow leopar...
  • Uninstall ToolV...
  • 中华人民共和国分省地图册V1....
  • 谷歌地球(收费版)的破解版【可...
  • Foxit Phantom P...
  • Windows优化大师v7.9...
  • CIPAddressCtrl类...
  • 安装软件时出现系统提示&quo...
  • XP与XP无线共享设置(笔记本...
  • ZineMaker目录模板大集...
  • 没有不可能 轻松实现PDG转P...
  • CString转char的方法...
  • [转]MSDN精简版、MSDN...
  • 将IE、FIREFOR (火狐...
  • VC多线程编程(转)
  • MyEclipse6.5下载地...
  • Diskeeper 2010 ...
  • 阅读(3191) | 评论(0) | 引用(0)
    发表评论
    表情
    emotemotemotemotemot
    emotemotemotemotemot
    emotemotemotemotemot
    emotemotemotemotemot
    emotemotemotemotemot
    打开HTML
    打开UBB
    打开表情
    隐藏
    记住我
    昵称   密码   游客无需密码
    网址   电邮   [注册]