Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- // include headers that implement a archive in simple text format
- #include <boost/archive/text_oarchive.hpp>
- #include <boost/archive/text_iarchive.hpp>
- /////////////////////////////////////////////////////////////
- // 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 & seconds;
- ++degrees;
- ++minutes;
- ++seconds;
- }
- public:
- int degrees;
- int minutes;
- float seconds;
- gps_position(){};
- gps_position(int d, int m, float s) :
- degrees(d), minutes(m), seconds(s)
- {}
- };
- int main() {
- // create and open a character archive for output
- std::ofstream ofs("filename");
- // create class instance
- const gps_position g(35, 59, 24.567f);
- // write the content of object
- std::cout << g.degrees << " " << g.minutes << " " << g.seconds << std::endl;
- boost::archive::text_oarchive oa(ofs);
- // write class instance to archive
- oa << g;
- // write the content of object
- std::cout << g.degrees << " " << g.minutes << " " << g.seconds << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement