Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check my simple MFC code please

Status
Not open for further replies.

wingedsoul

Programmer
Jan 21, 2006
4
CA
Hi I am coding a program but having a problem with saving and loading parts of a text file. What I made is rite below and an error occurs "SFile file;". What is wrong? And if you can please give me some lines for loading a text file. Thank you!



void CSavePane::OnSaveButton()
{
static char filter[]="Text Files(*.txt)|*.txt|All Files (*.*)|*.*||";

CFileDialog sDlg(FALSE,"txt","noname",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, filter);
if(sDlg.DoModal() != IDOK)
return;
CString str;
SFile file;
file.Open(sDlg.GetFileName(), CFile::modeCreate|CFile::modeWrite);
CArchive ar(&file, CArchive::load);
CArchive ar(&file, CArchive::store);
GetDlgItemText(IDC_DATA_EDIT,str);

ar<<str;
ar.Close();
file.Close();
SetDlgItemText(IDC_DATA_EDIT, "save ok!");

}
 
I think it should be

CFile file;

// Not SFile file;

file.Open( yada yada yada);
// something like this but don't expect it to compile
// without some work
CString s;
while( !file.eof() ) {
s = file.ReadLine();
// this is ugly mix of c and mfc
printf("%s\n", (LPCSTR)s);
}
file.Close();
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top