How can I read data from a text file in tab-delimited format?

Article ID: 93
Last updated: 22 Jun, 2018
Article ID: 93
Last updated: 22 Jun, 2018
Revision: 3
Views: 1870
Posted: 12 Jan, 2001
by Meltreger B.
Updated: 22 Jun, 2018
by Meltreger B.

Problem


How can I read data from a text file in tab-delimited format?


Cause



Action


The PasteTextFromBuffer() can paste the text values from a buffer with tab-delimited data into the grid. The following example demonstrates how you can load data from a text file:

void CGridSampleView::OnImportTextFile()
{
// pop-up file-open dlg to ask for location
CfileDialog dlgFile(
TRUE,
_T(".txt"),
NULL,
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
_T("Text Files (*.txt)|*.txt|All Files (*.*)|*.*||"));
if (dlgFile.DoModal() == IDCANCEL)
return;
CFile textFile;

if (!textFile.Open(dlgFile.GetFileName(), CFile::modeRead))
{

TCHAR sz[255];
wsprintf(sz, "File %s could not be opened!", dlgFile.GetFileName());
AfxMessageBox(sz);

return;

}

LPTSTR pszBuffer;
DWORD dwSize = textFile.GetLength();
pszBuffer = new TCHAR[dwSize];
textFile.Read(pszBuffer, dwSize);

PasteTextFromBuffer(pszBuffer, dwSize, CGXRange(0,1));
textFile.Close();

delete pszBuffer;

}

This article was:   Helpful | Not helpful
Report an issue
Article ID: 93
Last updated: 22 Jun, 2018
Revision: 3
Views: 1870
Posted: 12 Jan, 2001 by Meltreger B.
Updated: 22 Jun, 2018 by Meltreger B.

Others in this category