I need write some integer numbers to a CFile.
Following has some code. The ContactData.txt file has
been created in the same directory as *.cpp file.
int number = 300;
CFile cf;
if( cf.Open( "ContactData.txt",
CFile::modeWrite ) ){
char Data[] = "";
try{
cf.SeekToEnd();
cf.Write( Data, strlen( Data ) );
}
catch( CFileException *e ){
e->Delete();
}
}
Could any body tell me how to make the above code work
properly?
Thanks in advance.
Best wishes,
Daniel
Is there any data in the char array? As shown above it is empty and
therefore the Write statement will write 0 bytes. The easiest way to do
this is to use CString instead of char[], and use CStdioFile instead of
CFile. (CFile is for binary data, CStdioFile is for text data.) Then
you need to convert the integer into the CString before writing. The
CString Format function can be used for that.
--
Scott McPhillips [VC++ MVP]
then u can use CString::Format(itoa(...)) to store the
data and afterwards CString::GetBuffer() to get the
reasonable memory, write to the file and afterwards
CString::ReleaseBuffer() to clear memory.