I am doing my Project in VC++.net 2008. I want to load the datas to a List box from a text(.txt) file. So I have written the code as
the problem am facing is: it will work in the first time. If I tried it after clearing all the datas in Listbox..data doesnot loaded..Code:void CNewSerialPrintDlg::OnBnClickedBtnLdfile() { /*TODO: Add your control notification handler code here*/ CFileDialog FileDialog(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("Text File (*.txt)|*.txt||"),NULL,0,TRUE); if (FileDialog.DoModal() == IDCANCEL) return; m_parameterlist.ResetContent(); //CListBox m_parameterlist ASSERT(m_parameterlist.GetCount() == 0); _tcscpy(sFileName, FileDialog.GetFileName()); LoadFile.open(sFileName, ios::in | ios::beg); //initialised LoadFile as fstream in headerfile if(!LoadFile.is_open()) ::AfxMessageBox( _T("The file was not opened" )); parList.RemoveAll(); //the datas to ListBox is in CStringList parList while(!LoadFile.eof()) { LoadFile.getline(store_file,255,_T('\n')); parList.AddTail(store_file); m_parameterlist.AddString((LPCTSTR)store_file); } LoadFile.close(); }
I've used the same code in VC++6.0 and worked... bt here not... Wat change needed...




Reply With Quote
