0
class CMyFile { int a; wchar_t str [10]; public: CMyFile() { a = 12; wcscpy(str,L「ddddd」); } };如何在mfc中讀取類對象表單文件(使用CFile)?
我正在用以下方式編寫 CMyFile l_temp;
CFile myFile;
CFileException fileException;
if (!myFile.Open(pszFileName, CFile::modeCreate |
CFile::modeReadWrite, &fileException))
{
TRACE(L"Can't open file %s, error = %u\n",
pszFileName, fileException.m_cause);
}
else
{
myFile.Write((wchar_t*)&l_temp,sizeof(CMyFile));
myFile.Close();
}
但是當我讀取它不是讀correc噸值以下 類CMyFile { INT一個 讀取代碼中給出了 // abc obj; wchar_t str [10]; public: CMyFile() { // a = 12; // wcscpy(str,L「ddddd」); } };
CMyFile l_temp;
CFile myFile;
CFileException fileException;
if (!myFile.Open(pszFileName, CFile::modeCreate |
CFile::modeReadWrite, &fileException))
{
TRACE(L"Can't open file %s, error = %u\n",
pszFileName, fileException.m_cause);
}
else
{
myFile.Read((wchar_t*)&l_temp,sizeof(CMyFile));//not reading correctly
myFile.Close();
}