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

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

Recommended Answers

All 3 Replies

What errors if any are you getting? What line(s) is(are) the error(s) pointing to?

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.