转载自:http://www.programbbs.com/doc/2906.htm
发现对用CStdioFile 类读写文件还是很有帮助的
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"> </script> width="468" scrolling="no" height="60" frameborder="0" allowtransparency="true" hspace="0" vspace="0" marginheight="0" marginwidth="0" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-1818792399646005&dt=1182224265028&lmt=1181725066&alternate_ad_url=http%3A%2F%2Fwww.programbbs.com%2Fmyselfad.html&prev_fmts=728x90_as&format=468x60_as&output=html&correlator=1182224264950&url=http%3A%2F%2Fwww.programbbs.com%2Fdoc%2F2906.htm&ad_type=image&ref=http%3A%2F%2Fwww.google.cn%2Fsearch%3Fq%3DCStdioFile%2Bopen%2B%26complete%3D1%26hl%3Dzh-CN%26newwindow%3D1%26start%3D10%26sa%3DN&cc=51&flash=9&u_h=1024&u_w=1280&u_ah=957&u_aw=1280&u_cd=32&u_tz=480&u_his=1&u_java=true&u_nplug=27&u_nmime=148" name="google_ads_frame">
当前位置:
编程文档 >>
VC++ >> C/MFC - 文本文件的简单操作
C/MFC - 文本文件的简单操作
所属类别:
VC++
推荐指数:★★☆
文档人气:
34
本周人气:
6
发布日期:2007-6-13
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();
width="728" scrolling="no" height="90" frameborder="0" allowtransparency="true" hspace="0" vspace="0" marginheight="0" marginwidth="0" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-1818792399646005&dt=1182224264950&lmt=1181725066&format=728x90_as&output=html&correlator=1182224264950&url=http%3A%2F%2Fwww.programbbs.com%2Fdoc%2F2906.htm&ad_type=text&ref=http%3A%2F%2Fwww.google.cn%2Fsearch%3Fq%3DCStdioFile%2Bopen%2B%26complete%3D1%26hl%3Dzh-CN%26newwindow%3D1%26start%3D10%26sa%3DN&cc=51&flash=9&u_h=1024&u_w=1280&u_ah=957&u_aw=1280&u_cd=32&u_tz=480&u_his=1&u_java=true&u_nplug=27&u_nmime=148" name="google_ads_frame">
文档说明:
- 感谢您访问编程论坛,如果您发现错误或其它问题,请在论坛发帖或 写信 通知我们。
- 本站属于非营利性网站,如果我不慎侵犯了您的权力,希望您能谅解或通知我该如何处理。
- 欢迎广大作者或站点给我提供相关资料,谢谢支持!
width="728" scrolling="no" height="15" frameborder="0" allowtransparency="true" hspace="0" vspace="0" marginheight="0" marginwidth="0" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-1818792399646005&dt=1182224265106&lmt=1181725066&prev_fmts=728x90_as%2C468x60_as&format=728x15_0ads_al&output=html&correlator=1182224264950&url=http%3A%2F%2Fwww.programbbs.com%2Fdoc%2F2906.htm&ref=http%3A%2F%2Fwww.google.cn%2Fsearch%3Fq%3DCStdioFile%2Bopen%2B%26complete%3D1%26hl%3Dzh-CN%26newwindow%3D1%26start%3D10%26sa%3DN&cc=51&flash=9&u_h=1024&u_w=1280&u_ah=957&u_aw=1280&u_cd=32&u_tz=480&u_his=1&u_java=true&u_nplug=27&u_nmime=148" name="google_ads_frame">