类CMyFile { int a; wchar_t str [10]; 上市: 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.Write((wchar_t*)&l_temp,sizeof(CMyFile));
myFile.Close();
}
但是当我读它时,它并没有读取正确的值 阅读代码如下 类CMyFile { int a; // abc obj; wchar_t str [10]; 上市: 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();
}