流云の剑舞秋风

吾生也有涯 而知也无涯

博客园 首页 新随笔 联系 订阅 管理
//打开文件(modeCreate:文件不存在就创建文件,若存在而无modeNoTruncate标志则清空文件)
CFile file("text.txt",CFile::modeReadWrite|CFile::modeNoTruncate|CFile::modeCreate);
 
char pbuf[100];
 UINT nBytesRead
=file.Read(pbuf,100);
 
//AfxMessageBox(pbuf);

 strcpy(pbuf,
"this file is modified by yjm");
//写入文件(从当前位置)
 file.Write(pbuf,sizeof(pbuf));
 
//AfxMessageBox(pbuf);
 file.Close();
文件定位:
virtual LONG  Seek(LONG lOff,UINT nFrom);
作用:把文件位置指针相对移动一个偏移量;
参数:
nForm:标志移动的基准,可以取CFile::begin 
/ CFile::current / CFile::end,分别表示相对于文件头、当前位置、文件尾;
IOff:偏移量(可正可负)

LONG IOffset
=1000,IActual;
IActual
=file.Seek(IOffset,CFile::begin)
//指针相对文件头向后移动1000字节
其他函数:
SeekToBegin
SeekToEnd
GetPosition//得到当前文件指针位置
GetLength //得到文件长度
GetStatus // 得到文件属性
...
posted on 2005-05-16 14:20  流云  阅读(1159)  评论(0编辑  收藏  举报