0

Hello everyone!
I have created an editable list control (report style) with numbers. I want to save the content in a text file (each number below the other) and I used

void CDataDialog::OnBnClickedOk()
{
CStdioFile file("test.txt", CFile::modeCreate);

int nCount = m_List.GetItemCount();//m_List is control variable declared about list control
for (int x = 0; x < nCount; x++)
{
    CString strText = m_List.GetItemText(x, 0); // first column
    file.WriteString(strText);
}
file.Close();
}

but although it is compiled, it crashes. Could someone help please?

4
Contributors
3
Replies
30
Views
4 Months
Discussion Span
Last Post by thines01
0

"It craches" tells us nothing.
Be more specific.
Did you debug the thing? What are the error messages and codes? Etc.

0

How do you know the default directory?
It could be trying to save the file in an area where you don't have write-access.
Simply using "test.txt" without specifying the directory/folder leaves you at the mercy of the last file-pointer.

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.