|
Posted by £Ã£Î£¹£¹ on December 29, 2005, 10:28 pm
Please log in for more thread options
Hi:
I'm under VC.net/Smart phone project, and I have some trouble with file
operation, pls see the following code snippet
//Create Test.xml and write something into it, for example csXML =
"<Diary></Diary>"
CFile file;
if (!file.Open( TEXT("\Test.xml"), CFile::modeCreate | CFile::modeWrite))
{
return;
}
if (file.GetLength() == 0) //first time writing
{
file.Write((LPCTSTR)csXML, csXML.GetLength());
}
file.Close();
////////////////////
//Read content out of Test.xml but pBuffer only contains '<', why?
CFile file;
if (!file.Open( TEXT("\Test.xml"), CFile::modeRead) )
{
ASSERT(FALSE);
}
int nFileLen = (int)file.GetLength();
char* pBuffer = new char[nFileLen + 2];
nFileLen = file.Read( pBuffer, nFileLen );
file.Close();
pBuffer[nFileLen] = '';
pBuffer[nFileLen+1] = ''; // in case 2-byte encoded
|