tags:

views:

197

answers:

1

I am using MFC CFile Seek function. I have a problem about Seek out of file length.

CFile cfile;
BOOL bResult = cfile.Open(
L"C:\\2.TXT", 
CFile::modeReadWrite | 
CFile::modeCreate | 
CFile::modeNoTruncate | 
CFile::typeBinary | 
CFile::shareDenyNone);

cfile.Seek(10000, CFile::End);
cfile.Close();

MSDN: Remarks

The Seek function permits random access to a file's contents by moving the pointer a specified amount, absolutely or relatively. No data is actually read during the seek. If the requested position is larger than the size of the file, the file length will be extended to that position, and no exception will be thrown.

According to MSDN, the file length will be extended. However after cfile.Close(), the file remains the same. Why?Many thanks!

+1  A: 

I think MSDN misstated the matter slightly. When you call Seek the file pointer is adjusted, but the actual file on the disk doesn't change yet. If you call Write after that, then the actual file will become a sparse file (on NTFS) or a longer file (on FAT), with the expected length.

There don't seem to be any definite rules.

Windows programmer
Many Thanks! I see