MFC - Write/Create File
yuibox March 19th, 2008
This is a simple sample code of how to create and write a file. Sometimes this is really trivial but when u switch languages all the time, we tend to forget a bit the syntax ^__^
[source:c++]
//Open/Write File
CStdioFile Outputfile;
CFileException FileExc;
UINT nOpenFlags;
//Creates the File with the Date/Time
COleDateTime::GetCurrentTime();
COleDateTime odt = COleDateTime::GetCurrentTime();
//Date/Time Format
CString str1 = odt.Format(”%B_%d_%Y_%H_%M_%S” );
szFileName =”LogFile_” + str1+ “.txt” ;
nOpenFlags = CFile::modeWrite | CFile::modeCreate;
//If any errors @ opening file. displays msg.
if (!Outputfile.Open( (”GPSLog_” + str1+ “.txt”), nOpenFlags, &FileExc)) {
FileExc.ReportError();
return;
}
//Writes in the file
Outputfile.WriteString(”WRITE W/E TEXT HERE”+’\n’);
//closes it
Outputfile.Close(); [/source]
Stumble it!
April 23rd, 2008 at 7:07 pm
can you give me code to create a notepad with MFC?, I make a exercise about this. Thanks
April 30th, 2008 at 7:45 am
Hey! you can find a example in this article : http://www.yuibox.com/2008/03/18/mfc-openfile-in-notepad/#more-26