2011-07-12 85 views
0

我想在我的課堂裏得到兩個數組來使用boost序列化庫。我可以很好地保存數據,但出於某種原因,我無法加載它。我認爲這與ia >> *這是一致的。但我不知道如何解決它。任何人都可以將我指向正確的軌道?升壓序列化問題

class foo 
{ 

private: 
int tileType[512]; 
int tileSubType[512]; 

friend std::ostream & operator<<(std::ostream &os, const foo &gp); 
friend class boost::serialization::access; 
template<class Archive> 
void serialize(Archive & ar, const unsigned int version) 
{ 
    ar & tileType; 
    ar & tileSubType; 
} 

public: 
foo(); 

void loadType(string data) 
{ 
    std::stringstream is(data); 

    boost::archive::text_iarchive ia(is); 
    ia >> *this; 
} 

string saveType() 
{ 
    stringstream ss(stringstream::in | stringstream::out); 
    boost::archive::text_oarchive oa(ss); 
    oa << this; 

    return ss.str().c_str(); 
} 

}; 
+0

編譯失敗?運行時失敗?你的問題是什麼? –

回答

0

你試過

oa << *this; 

您正在保存指針但加載到引用中,我想這不是你想要的,對吧?

0

我遇到了一些問題,試圖在檔案中使用>><<操作符。嘗試在這兩種情況下使用&運算符,然後查看是否可以爲您解決問題。