1 | #include <iostream>
|
---|
2 | #include <fstream>
|
---|
3 |
|
---|
4 | #include <boost/archive/xml_oarchive.hpp>
|
---|
5 | #include <boost/archive/xml_iarchive.hpp>
|
---|
6 | #include <boost/archive/xml_archive_exception.hpp>
|
---|
7 |
|
---|
8 | class Seri
|
---|
9 | {
|
---|
10 | int mem;
|
---|
11 | friend class boost::serialization::access;
|
---|
12 |
|
---|
13 | template<class Archive>
|
---|
14 | void serialize(Archive & ar, const unsigned int version)
|
---|
15 | {
|
---|
16 | ar & boost::serialization::make_nvp("mem", mem);
|
---|
17 | }
|
---|
18 | };
|
---|
19 |
|
---|
20 |
|
---|
21 | int main()
|
---|
22 | {
|
---|
23 | Seri ser;
|
---|
24 | // uncomment this if you first want to write an xml file instead of only read it
|
---|
25 | /* {
|
---|
26 | std::ofstream ofs("mismatch.xml");
|
---|
27 | boost::archive::xml_oarchive arch(ofs);
|
---|
28 | arch << boost::serialization::make_nvp("testobject", ser);
|
---|
29 | }
|
---|
30 | */
|
---|
31 | {
|
---|
32 | std::ifstream ifs("mismatch.xml");
|
---|
33 | boost::archive::xml_iarchive arch(ifs);//, boost::archive::no_xml_tag_checking);
|
---|
34 |
|
---|
35 | try
|
---|
36 | {
|
---|
37 | arch >> boost::serialization::make_nvp("seriobject", ser);
|
---|
38 | }
|
---|
39 | catch (boost::archive::xml_archive_exception const& e)
|
---|
40 | {
|
---|
41 | std::cerr << e.what() << "\n";
|
---|
42 | }
|
---|
43 | }
|
---|
44 | }
|
---|