I am using Visual C++ CFile.
I open a file, write some data, then read some data, must I flush the data between the write and read operations:
CFile File;
CByteArray Buf1, Buf2;
Buf1.SetSize(512);
memset(Buf1.GetData(), 1, Buf1.GetSize());
Buf2.SetSize(512);
memset(Buf2.GetData(), 0, Buf2.GetSize());
if (File.Open(_T("E:\Temp\1.dat"), CFile::modeCreate | CFile::modeReadWrite | CFile::shareDenyNone))
{
File.Seek(0, CFile::begin);
File.Write(Buf1.GetData(), Buf1.GetSize());
// Need I flush the data before starting the read
// File.Flush();
File.Seek(0, CFile::begin);
File.Read(Buf2.GetData(), Buf2.GetSize());
if (memcmp(Buf1.GetData(), Buf2.GetData(), Buf1.GetSize()) == 0)
AfxMessageBox(_T("Same"));
}
It seems without the flush, the read data is also same as the written data.