i have a problem with csv file reading. I’m pretty new to mfc and i hope someone can help me. So…i have a button and with it i open file dialog and choose csv file. In csv file i have diferent shapes(rectangle,ellipse,pollygon) with color and position info(separtor is ;). Now i need to show this informations in a ListBox and here i’m stuck. I got so far(code)…and i don’t know it’s ok and i can’t find any good help so i hope someone can give me a hint.
void CDialogDrawing::OnBnClickedButton2()
{
TCHAR filtri[] = _T("CSV files (*.csv)|*.csv||");
CString path;
CFileDialog dlg(TRUE, _T("csv"), _T("*.csv"), OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, filtri);
dlg.m_ofn.lpstrTitle = _T("Open...");
if(dlg.DoModal() == IDOK) //OK
{
path = dlg.GetPathName();
//
CStdioFile readFile;
CFileException fileException;
CString strLine;
if(readFile.Open(path, CFile::modeRead, &fileException))
{
while (readFile.ReadString(strLine));
{
seznamLikov.AddString(strLine);
}
}
else
{
CString strErrorMsg;
strErrorMsg.Format(_T("Can't open file %s , error : %u"), path, fileException.m_cause);
AfxMessageBox(strErrorMsg);
}
readFile.Close();
}
}
Trailing semi-colon after the
while:remove it as it is equivalent to:
meaning
AddString()will be invoked only once, afterReadString()fails.