Hi to all,
I am having a problem with boost serialization on version 1.58.0
The code at the end of the post is nearly the same found at the beginning
of the page
libs/serialization/doc/index.html (the 'Very simple case'). The only
relevant difference is
the use of the wide char version of archive (and fstream) and an additional
'name' text field
in the sample structure. This text contains a cyrillic character (the
capitol 'D')
The problem I am having with this code is that it throws an exception when
using version 1.58.0,
while everything is OK if I compile/link against version 1.57.0
The problem seems to be related with character conversion: the library
seems to convert
non ascii chars to local default codepage, instead of UTF-8. So everything
looks fine as long
as I use characters convertable to my codepage. I gave a look at the
differencies between
the two versions, but they are definitely beyond my reach...
Tests done on windows with MSVC2013 and MSVC2008
Marco
#include <fstream>
// include headers that implement a archive in simple text format
#include
#include
/////////////////////////////////////////////////////////////
// gps coordinate
//
// illustrates serialization for a simple type
//
class gps_position
{
private:
friend class boost::serialization::access;
// When the class Archive corresponds to an output archive, the
// & operator is defined similar to <<. Likewise, when the class
Archive
// is a type of input archive the & operator is defined similar to >>.
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & degrees;
ar & minutes;
ar & name;
ar & seconds;
}
int degrees;
int minutes;
std::wstring name ;
float seconds;
public:
gps_position(){};
gps_position(int d, int m, float s, const std::wstring &n) :
degrees(d), minutes(m), seconds(s), name(n)
{}
};
int main() {
// create and open a character archive for output
std::wofstream ofs("filename");
// create class instance
const gps_position g(35, 59, 24.567f, L"AДbc");
// save data to archive
{
boost::archive::text_woarchive oa(ofs);
// write class instance to archive
oa << g;
// archive and stream closed when destructors are called
}
// ... some time later restore the class instance to its orginal state
gps_position newg;
{
// create and open an archive for input
std::wifstream ifs("filename");
boost::archive::text_wiarchive ia(ifs);
// read class state from archive
ia >> newg;
// archive and stream closed when destructors are called
}
return 0;
}