【问题标题】:how to read a class object form file (using CFile) in mfc?如何在 mfc 中读取类对象表单文件(使用 CFile)?
【发布时间】:2010-12-03 10:28:40
【问题描述】:

类 CMyFile { 诠释一个; 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 { 诠释一个; //abc 对象; 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();
    }

【问题讨论】:

    标签: mfc


    【解决方案1】:

    您好,您可以使用 MFC serialization

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-04
      • 2011-01-20
      • 1970-01-01
      • 2013-01-27
      • 2014-05-30
      • 1970-01-01
      相关资源
      最近更新 更多