CStdioFile - Can't read what I have just written
Hello,
I have a program that uses a text file for configuration. In my program
there is a meny where the user can change the configuration. the
configuration is written to a text file using CStdioFile, e.g.
CStdioFile f;
BOOL brc = f.Open(m_filepath,CFile::modeCreate |
CFile::modeWrite|CFile::typeText);
if (brc)
{
// OffsetX
c_offsetX.GetWindowText(value);
buf.Format(_T("OffsetX=%s\n"),value);
f.WriteString(buf);
<snipped a number of simular code>
f.Flush();
f.Close();
}
Then in a another part of the program I read this text file:
CStdioFile f;
BOOL brc = f.Open(fpath,CFile::modeRead|CFile::typeText);
if (brc)
{
CString buf,key,value;
int pos=0;
// OffsetX
f.ReadString(buf);
key = buf.Tokenize(_T("="),pos);
value = buf.Tokenize(_T("="),pos);
m_offsetX = _tstof(value);
<snipped a number of simular code>
f.Close();
}
My problem is that when I have changed a value, using the first code, the
changes will not be read by the second code! If I restart my program then
it will read the changes!
I thought that this was Windows buffering the file when I'm writing to it,
but Flush() should take care of that.
Is there something I need to do to stop windows from buffering the file
when reading?
// Anders
--
English is not my first, or second, language
so anything strange, or insulting, is due to
the translation.
Please correct me so I may improve my English!