المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : how to write/read in text file with mfc project??



C++ Programming
10-11-2011, 11:51 PM
I'm trying to read text from a text file. I look for in msdn how to read and write in text file, and I found this:
http://msdn.microsoft.com/es-es/library/6337eske.aspx[^ (http://msdn.microsoft.com/es-es/library/6337eske.aspx)]

I made this funtion to read from my text file:

void CDlgResultados::loadFromFile(void){ CString path= GetUserHomeDir() + _T("\\Documents\\file.txt"); TCHAR szBuffer[256]; UINT nActual = 0; CFile myFile; if ( myFile.Open(path, CFile::modeCreate | CFile::modeRead ) ) { myFile.Write( szBuffer, sizeof( szBuffer ) ); myFile.Flush(); myFile.Seek( 0, CFile::begin ); nActual = myFile.Read( szBuffer, sizeof( szBuffer ) ); } m_Edit.SetWindowTextW(szBuffer);}

But when I run the app and I press the button to read the file, I get a error that it said:
You dont have acces to this file.