|
-
July 28th, 2009, 05:42 AM
#16
Re: Save button MFC
 Originally Posted by Elrond
... Note that WriteString does not add the end of line characters, so you would nee to do it yourself when you need it:
Code:
CString str = _T("String to write\r\n");
file.WriteString(str);
This code is not 100% correct.
you should NOT add CR ('\r') character yourself, only LF ('\n'). CStdioFile::WriteString will then replace
... any newline character ... written to the file as a carriage return–linefeed pair.
So, the correct code is:
Code:
CString str = _T("String to write\n");
file.WriteString(str);
Victor Nijegorodov
-
July 28th, 2009, 09:33 PM
#17
Re: Save button MFC
Hi,
Do i still need mode create if i am just saving all the data into a file i already created.Also which is the line that opens up the directory so that u can save it to your file?Do i have to include seektoend() below
file.Open(filename, CFile::modeCreate | CFile::modeNoTruncate | CFile::modeWrite);
Thanks
nancy
-
July 29th, 2009, 02:45 AM
#18
Re: Save button MFC
 Originally Posted by nancy87
... Also which is the line that opens up the directory so that u can save it to your file?
You don't need to "open a directory".
Just use CFileDialog::GetPathName to obtain the full path name of a file and then pass this full path name to CStdIo::Open
 Originally Posted by nancy87
... Do i have to include seektoend() below
file.Open(filename, CFile::modeCreate | CFile::modeNoTruncate | CFile::modeWrite);
Yes, if you want to append new data to the old file.
Victor Nijegorodov
-
July 29th, 2009, 10:48 PM
#19
Re: Save button MFC
hi guys
may i know which part i went wrong my code is here
void CabcdeDlg::OnBnClickedButton1()
{
CString strTextTime;
m_Time.GetWindowText(strTextTime);
CStdioFile File;
file.Open(lpszfilename, CFile::modeCreate | CFile::modeNoTruncate | CFile::modeWrite);
file.SeekToEnd();
file.Write(" hello world");
CString str = _T("String to write\n");
file.WriteString(str);
file.Close();
}
Last edited by kacaka; August 3rd, 2009 at 08:18 PM.
-
July 30th, 2009, 12:43 AM
#20
Re: Save button MFC
Do not forget to close file when writting string into a file.
Little by little one goes far
Keep moving.......!
Nothing is impossible !
-
July 30th, 2009, 02:46 AM
#21
Re: Save button MFC
 Originally Posted by kacaka
hi guys
may i know which part i went wrong my code is here
...
What is the problem?
Besides:
- The variable filename is not defined.
- You have to use CFileException to know whether your file operations succeded or not. See the code examples in MSDN articles CFile::Open and CStdioFile::CStdioFile
Victor Nijegorodov
-
August 3rd, 2009, 03:15 AM
#22
Re: Save button MFC
Hi,victorN
Understand that you do not want to spoonfeed me with giving me the code,but after trying quite long i still cant compile and my code shows lots of arrow care to rpovide more help??sorry i started this nt long ago.
-
August 3rd, 2009, 03:28 AM
#23
Re: Save button MFC
 Originally Posted by kacaka
... after trying quite long i still cant compile and my code shows lots of arrow care to rpovide more help??
But you haven't shown your actual code yet! Nor showed you the exact compile errors!
So how could we help you more?
Victor Nijegorodov
-
August 3rd, 2009, 08:22 PM
#24
Re: Save button MFC
hi,
my code as above, may i ask why there are error c2228 like left of 'seekToEnd' must have class /struct union. the same error appears for 'write' n 'close','writestring',error c2065 lpszfileName undeclared identifier'writestring'.
The variable filename is not defined. ?? may i know hw to define tis.
for point 2
You have to use CFileException to know whether your file operations succeded or not. See the code examples in MSDN articles CFile::Open and CStdioFile::CStdioFile
CFileException Exception;
CFile File;
if(File.Open("c:\\data.txt", CFile::modeRead, &Exception) == FALSE)
{
may i know whether the code is correct .
-
August 3rd, 2009, 08:27 PM
#25
Re: Save button MFC
 Originally Posted by kacaka
hi,
my code as above, may i ask why there are error c2228 like left of 'seekToEnd' must have class /struct union. the same error appears for 'write' n 'close','writestring',error c2065 lpszfileName undeclared identifier'writestring'.
The variable filename is not defined. ?? may i know hw to define tis.
for point 2
You have to use CFileException to know whether your file operations succeded or not. See the code examples in MSDN articles CFile::Open and CStdioFile::CStdioFile
CFileException Exception;
CFile File;
if(File.Open("c:\\data.txt", CFile::modeRead, &Exception) == FALSE)
{
may i know whether the code is correct .
You didn't show any of the code that generated those errors. Keep in mind though that C++ is case sensitive.
-
August 3rd, 2009, 10:02 PM
#26
Re: Save button MFC
hi ,
i have solved the errors now and it works.any question i will post on a new thread thank you everyone
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|