| 1 | #include <string>
|
|---|
| 2 | #include <sstream>
|
|---|
| 3 | #include <iostream>
|
|---|
| 4 | #include <fstream>
|
|---|
| 5 |
|
|---|
| 6 | #include <boost/date_time/gregorian/greg_serialize.hpp>
|
|---|
| 7 | #include <boost/date_time/gregorian/gregorian.hpp>
|
|---|
| 8 |
|
|---|
| 9 | #include <boost/archive/text_oarchive.hpp>
|
|---|
| 10 | #include <boost/serialization/nvp.hpp>
|
|---|
| 11 |
|
|---|
| 12 | struct User
|
|---|
| 13 | {
|
|---|
| 14 | std::string name;
|
|---|
| 15 | boost::gregorian::date dateOfBirth;
|
|---|
| 16 |
|
|---|
| 17 | template<typename Archive>
|
|---|
| 18 | void serialize(Archive& ar, const unsigned int)
|
|---|
| 19 | {
|
|---|
| 20 | ar & BOOST_SERIALIZATION_NVP(name)
|
|---|
| 21 | & BOOST_SERIALIZATION_NVP(dateOfBirth);
|
|---|
| 22 | }
|
|---|
| 23 | };
|
|---|
| 24 |
|
|---|
| 25 | int main(int argc, const char *argv[])
|
|---|
| 26 | {
|
|---|
| 27 | User u {"stac", boost::gregorian::date(1981, 6, 19)};
|
|---|
| 28 | /* std::ostringstream os; */
|
|---|
| 29 | std::ofstream os("user.ser");
|
|---|
| 30 | {
|
|---|
| 31 | boost::archive::text_oarchive ar(os);
|
|---|
| 32 | ar << u;
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | return 0;
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|