Me
2013-02-10 22:04:50 UTC
I am using Visual Studio 2012 VC++
CFile CString save problem
I have the following:
*************************************************************************************
CFile f;
int flen;
CString Afile;
CString Ptype;
CString Tstr1;
// m_strPressType is a control variable of an edit box
m_strPressType.GetWindowTextW(Ptype); //retrieve contents of editbox
Tstr1.Format(_T("PressType %s"), Ptype); //create save string
// verify length of the save file which shows correct length
flen = Tstr1.GetLength();
Tstr2.Format(_T("flen = %d"), flen);
AfxMessageBox(Tstr2);
//save string to file
CFileException e;
Afile.Format(_T("%soptions.ini"), BasePath); //BasePath is type char
"C:\MyData\"
if(!f.Open(Afile, CFile::modeCreate || CFile::modeWrite, &e))
afxDump << "File could not be opened " << e.m_cause << "\n"; //no error
displayed
f.Write(Tstr1, flen); //write the string to file
f.Close();
*************************************************************************************
The filename is created successfully but the contents are incorrect.
flen is displayed as 20 bytes which would be correct but the file saved is
218 bytes?
The contents SHOULD BE:
PressType TeleColor2
But the actual contents is:
P r e s s T y p e
garbage follows here after CRLF for the rest of the 218 bytes.....
What am I doing wrong?
CFile CString save problem
I have the following:
*************************************************************************************
CFile f;
int flen;
CString Afile;
CString Ptype;
CString Tstr1;
// m_strPressType is a control variable of an edit box
m_strPressType.GetWindowTextW(Ptype); //retrieve contents of editbox
Tstr1.Format(_T("PressType %s"), Ptype); //create save string
// verify length of the save file which shows correct length
flen = Tstr1.GetLength();
Tstr2.Format(_T("flen = %d"), flen);
AfxMessageBox(Tstr2);
//save string to file
CFileException e;
Afile.Format(_T("%soptions.ini"), BasePath); //BasePath is type char
"C:\MyData\"
if(!f.Open(Afile, CFile::modeCreate || CFile::modeWrite, &e))
afxDump << "File could not be opened " << e.m_cause << "\n"; //no error
displayed
f.Write(Tstr1, flen); //write the string to file
f.Close();
*************************************************************************************
The filename is created successfully but the contents are incorrect.
flen is displayed as 20 bytes which would be correct but the file saved is
218 bytes?
The contents SHOULD BE:
PressType TeleColor2
But the actual contents is:
P r e s s T y p e
garbage follows here after CRLF for the rest of the 218 bytes.....
What am I doing wrong?