我自己定义了一个类CTemp.class CTemp
{
CString str1;
CString str2;
CString str3;
CString str4;
}然后在doc中有个CTemp集合类CArray<CTemp,CTemp>的变量mArrTemp.
在序列化文件时,要把mArrTemp序列化。
我直接在doc的Serialize函数中调用mArrTemp.Serialize(ar)。问题出在打开序列化文件,并没有按照mArrTemp保存的数据反序列化,只有mArrTemp中元素的个数是正确的,元素内的str1/str2...等都是空值。
我在用CArray<CTemp,CTemp>序列化的过程中,哪里错了,望大侠指点!
{
CString str1;
CString str2;
CString str3;
CString str4;
}然后在doc中有个CTemp集合类CArray<CTemp,CTemp>的变量mArrTemp.
在序列化文件时,要把mArrTemp序列化。
我直接在doc的Serialize函数中调用mArrTemp.Serialize(ar)。问题出在打开序列化文件,并没有按照mArrTemp保存的数据反序列化,只有mArrTemp中元素的个数是正确的,元素内的str1/str2...等都是空值。
我在用CArray<CTemp,CTemp>序列化的过程中,哪里错了,望大侠指点!
class CMyObject : public CObject
{
// ...Member functions
public:
CMyObject() { }
virtual void Serialize( CArchive& ar ) { }// Implementation
protected:
DECLARE_SERIAL( CMyObject )
};
IMPLEMENT_SERIAL(CMyObject,CObject,1)
那些CString是否要单独处理?
void CMFCDlg::OnButton1()
{
//串行化写入到文件
CFile theFile;
theFile.Open("c:\\1.dat", CFile::modeCreate |CFile::modeWrite);
CArchive archive(&theFile, CArchive::store); //构造一个array
MY_TYPE my;//自定义类型
CArray<MY_TYPE, MY_TYPE&> arr;
for (int i = 0;i<10;i++)
{
my.z = my.y = my.x = i;
arr.Add(my);
} //串行化写入
arr.Serialize(archive);
} void CMFCDlg::OnButton2()
{
//串行化输出到界面
CFile theFile;
theFile.Open("c:\\1.dat", CFile::modeRead);
CArchive archive(&theFile, CArchive::load);
//构造对象
CArray<MY_TYPE, MY_TYPE&> arr;
//串行化输出
arr.Serialize(archive);
CString str;
str.Format("%d", arr.GetSize());
AfxMessageBox(str);
}
我和你的用法很相似,除了MY_TYPE中是int类型,而我的是CString类型。可我的反序列化失败了
在在连续两个CSting之间加入一个int变量保存试试