I have got a question about the MFC CFile write function.
I am learning about MFC application and stuck at this Save As and write function.
When I click the TestButton, a save as dialog box would pop out prompting to save as txt file.
void CLearnDlg::OnBnClickedButtonTest()
{
CString m_strPathName;
char* File;
TCHAR szFilters[] =
_T ("Text files (*.txt)¦*.txt¦All files (*.*)¦*.*¦¦");
CFileDialog dlg (FALSE, _T ("txt"), _T ("*.txt"),
OFN_OVERWRITEPROMPT, szFilters);
if (dlg.DoModal () == IDOK)
m_strPathName = dlg.GetPathName();
CFile DataFile(m_strPathName, CFile::modeReadWrite | CFile::modeCreate);
char buffer0[100] = "TEST0";
char buffer1[100] = "TEST1";
int GetLength;
for (int i=0; i<2; i++)
{
File = (("%S, %S\n\n"), buffer0, buffer1);
GetLength = strlen(File);
DataFile.Write(File, GetLength);
}
DataFile.Close();
MessageBox(_T("OK"));
}
Question is how do I write two buffer together into a single File
then write it into the DataFile
and making a new line every time it write?
The output file is saved but only one buffer (TEST1) is saved twice without going to a new line.