I have the following code serialising shared_ptr's to fstream and reading
them back correctly. When I switch to using a stringstream (invert
comments) I get a null value in "str" following serialisation. I noticed
someone had a similar issue previously and solved it (but didn't explain
how). Serialising/de-serialising between stringstream works fine when the
iostreams are avoided.
Could someone point out what I'm doing wrong please?
Regards,
John
Using boost_1_33_1 on vc++2005 (8.0)
// test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include
#include
/*//*/#include <fstream>
//#include <sstream>
#include <iostream>
#include
#include
#include
#include
struct simple
{
simple() : i_(1){}
simple(int i) : i_(i){}
int i_;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & BOOST_SERIALIZATION_NVP(i_);
}
};
int _tmain(int argc, _TCHAR* argv[])
{
//std::string str;
{
boost::shared_ptr<simple> s(new simple(2));
std::vector vec;
for (int j = 0; j < 100; j++)
{
vec.push_back(s);
}
/*//*/std::ofstream os("c:/test_ser_shared_ptr.xml",
std::ios_base::binary);
//std::ostringstream os;
boost::iostreams::filtering_ostream out;
out.push(boost::iostreams::gzip_compressor());
out.push(os);
boost::archive::xml_oarchive oa(out);
oa & BOOST_SERIALIZATION_NVP(vec);
//str = os.str();
}
{
std::vector vec;
/*//*/std::ifstream is("c:/test_ser_shared_ptr.xml",
std::ios_base::binary);
//std::istringstream is(str);
boost::iostreams::filtering_istream in;
in.push(boost::iostreams::gzip_decompressor());
in.push(is);
boost::archive::xml_iarchive ia(in);
ia & BOOST_SERIALIZATION_NVP(vec);
int i = (*(vec.begin()))->i_;
}
return 0;
}
---
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
Please refer to http://www.db.com/en/content/eu_disclosures.htm for additional EU corporate and regulatory disclosures.