I have an error
-
Hi all !! I practise VC. When I code my program to create a file. The first time when I click my button2 (create file) I receive a error "access pathdir to file is denied" but I can create file at the second click. I don't know why ??? Please,I need help !! This's my code when click button2, I use MFC wizard (use dialogbase) void CTestDlg::OnButton2() { // TODO: Add your control notification handler code here char filename[100]; GetCurrentDirectory(100,filename); strcat(filename,"\\RongVang.dat"); CFile f; if(!f.Open(filename,CFile::modeReadWrite)) f.Open(filename,CFile::modeCreate); f.SeekToEnd(); char s[100]; strcpy(s,"Test Create file"); f.Write(s,100); } -- modified at 22:36 Sunday 16th October, 2005
-
Hi all !! I practise VC. When I code my program to create a file. The first time when I click my button2 (create file) I receive a error "access pathdir to file is denied" but I can create file at the second click. I don't know why ??? Please,I need help !! This's my code when click button2, I use MFC wizard (use dialogbase) void CTestDlg::OnButton2() { // TODO: Add your control notification handler code here char filename[100]; GetCurrentDirectory(100,filename); strcat(filename,"\\RongVang.dat"); CFile f; if(!f.Open(filename,CFile::modeReadWrite)) f.Open(filename,CFile::modeCreate); f.SeekToEnd(); char s[100]; strcpy(s,"Test Create file"); f.Write(s,100); } -- modified at 22:36 Sunday 16th October, 2005
-
the filename return format is not like this"C:\\ adir" it return format is "C:\adir" it can't use as a parameter in F.Open Function . d
-
Hi all !! I practise VC. When I code my program to create a file. The first time when I click my button2 (create file) I receive a error "access pathdir to file is denied" but I can create file at the second click. I don't know why ??? Please,I need help !! This's my code when click button2, I use MFC wizard (use dialogbase) void CTestDlg::OnButton2() { // TODO: Add your control notification handler code here char filename[100]; GetCurrentDirectory(100,filename); strcat(filename,"\\RongVang.dat"); CFile f; if(!f.Open(filename,CFile::modeReadWrite)) f.Open(filename,CFile::modeCreate); f.SeekToEnd(); char s[100]; strcpy(s,"Test Create file"); f.Write(s,100); } -- modified at 22:36 Sunday 16th October, 2005
-
Why do you open the file two times? i think there you get the error.
if(!f.Open(filename,CFile::modeReadWrite)) f.Open(filename,CFile::modeCreate);
Try this:if(!f.Open(filename,CFile::modeCreate | CFile::modeReadWrite))
if(!f.Open(filename,CFile::modeCreate | CFile::modeReadWrite)) f.Open(filename,CFile::modeCreate); The first click it will create file. I want at the second click, third,4,5,.... click in button2, it will append my file, not delete and create new file like above !! Can you help me ... !!!!!!!!!!!!
-
if(!f.Open(filename,CFile::modeCreate | CFile::modeReadWrite)) f.Open(filename,CFile::modeCreate); The first click it will create file. I want at the second click, third,4,5,.... click in button2, it will append my file, not delete and create new file like above !! Can you help me ... !!!!!!!!!!!!
CString filename = _T("C:\\RongVang.txt"); CStdioFile f; if(!f.Open(filename,CFile::modeReadWrite)) f.Open(filename,CFile::modeCreate|CFile::modeReadWrite); f.SeekToEnd(); CString s = _T("Test Create file\n"); f.WriteString(s);
dont forget to close your file. -
if(!f.Open(filename,CFile::modeCreate | CFile::modeReadWrite)) f.Open(filename,CFile::modeCreate); The first click it will create file. I want at the second click, third,4,5,.... click in button2, it will append my file, not delete and create new file like above !! Can you help me ... !!!!!!!!!!!!
vhazell wrote:
I want at the second click, third,4,5,.... click in button2, it will append my file, not delete and create new file like above !!
Then use:
if (f.Open(filename, CFile::modeCreate | CFile::modeReadWrite | CFile::modeNoTruncate) != FALSE)
{
f.SeekToEnd();
...
}
"Take only what you need and leave the land as you found it." - Native American Proverb