#include #include #pragma warning (disable:4267) #define PORTABLE_ARCHIVE #ifdef PORTABLE_ARCHIVE #include #include #else #include #include #endif ///////////////////////////////////////////////////////////// // 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 void serialize(Archive & ar, const unsigned int version) { ar & degrees; ar & minutes; ar & seconds; } int degrees; int minutes; float seconds; public: gps_position(){}; gps_position(int d, int m, float s) : degrees(d), minutes(m), seconds(s) {} }; int main() { // create class instance const gps_position g(35, 59, 24.567f); // save data to archive { std::ofstream ofs("C:/!Données MVI/Temp/bin.ar", std::ios::binary); #ifdef PORTABLE_ARCHIVE eos::portable_oarchive oa(ofs); #else boost::archive::binary_oarchive oa(ofs); #endif oa << g; } // ... some time later restore the class instance to its orginal state gps_position newg; { std::ifstream ifs("C:/!Données MVI/Temp/bin.ar", std::ios::binary); #ifdef PORTABLE_ARCHIVE eos::portable_iarchive ia(ifs); #else boost::archive::binary_iarchive ia(ifs); #endif ia >> newg; } return 0; }