开发者

how to read a class object form file (using CFile) in mfc?

class CMyFile { int a; wchar_t str[10]; public: CMyFile() { 开发者_高级运维 a = 12; wcscpy(str, L"ddddd"); } };

i am writing in following way 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();
    }

but when i reading it is not reading correc t values reading code is given below class CMyFile { int a; //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();
    }


Hi you can use MFC serialization

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜