Save text from CList into file
Hi, guys;
I found a small problem with this. I thought it wasn't important but to
be honest it's becoming a real pain in the ass.
The question is the following:
I've got a Clist with several lines created in the Dialog. At the end
of the dialog, I want to save that text in a file. The code is this:
void CTranslator::OnEditorEnd()
{
// TODO: Add your command handler code here
char szFilter[] = " *.txt";
CFileDialog FileDlg( TRUE, NULL, NULL, OFN_HIDEREADONLY, szFilter);
if (FileDlg.DoModal() == IDOK)
{
try
{
CFile cf(FileDlg.GetPathName() + ".txt", CFile::modeCreate |
CFile::modeWrite);
CString text;
cf.Write("\r\n",4);
for (int a = 0 ; a < line_t ; a++) // line_t is the last line in the
Clist
{
m_cLow.GetText(a, text);
cf.Write(text, text.GetLength());
cf.Write("\r\n", 4);
}
cf.Close();
}
catch (CFileException *e)
{
e->Delete();
MessageBox("Error saving file");
}
}
}
The big problem is that, I don't know why, two blank spaces are added
at the beginning of each line in the file. It's more than an aesthetic
question because the lines saved are part of a code that the reader
doesn't understand when it finds the blank spaces.
Another less important question is how I can open a "save Dialog"
instead of a "open dialog", because doing it the way I do, the dialog
is an "open dialog".