Re: CStdioFile - Can't read what I have just written
It's hard to know what's happening just from the information you provided
but if I was having this issue on my machine, I'd start by tracing through
the first code to ensure everything runs correctly (are your strings
correctly formed, does Open() return true, what is your resulting filename).
Next, I'd find the file I wrote and examine that using NotePad or something.
And, if that looked okay, I'd then trace through the second code and see
what part of that is not working.
There are too many variables left unanswered to debug this from your post,
but it sounds like your next step in development skills is to become
proficient at using the debugger, which is very capable and useful.
--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
"Anders Eriksson" <andis59@gmail.com> wrote in message
news:13rx69969isnc$.dlg@ostling.com...
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!