关于读文件的一个问题
在一个文件中有二万多行记录;
而最后一行有重要的数据,
我怎么快速的读取最后一行的数据;
如果用CFile::SeekToBegin()就到了文件尾了
[解决办法]
CFile::SeekToEnd()是到文件尾,往回读取
[解决办法]
CFile fp;
if((fp.Open( "a.txt ", CFile::modeRead)) != NULL)
{
string str;
string::size_type pos;
long step = 20;
char ch[100];
do
{
fp.Seek(-step, CFile::end);
UINT nBytesRead = fp.Read(ch, step);
str = ch;
pos = str.find_last_of( "\n ");
if(pos != string::npos)
break;
step += 20;
} while(1);
//str or ch中pos 后面就是你要的最后一行的数据.
}