#include #include #include #include #include #include #include #include void test_binary (float & f) { using namespace std ; std::ofstream ofs("val.bin"); boost::archive::binary_oarchive oa(ofs,std::ios::binary); oa<< f ; ofs.close(); std::cout << "Valeur serialisee binary " << f << std::endl ; std::ifstream ifs("val.bin"); boost::archive::binary_iarchive ia(ifs,std::ios::binary); float f1; ia >> f1; if (ifs.fail()) { cout << "badbit " << ( ifs.rdstate( ) & ios::badbit ) << endl; cout << "failbit " << ( ifs.rdstate( ) & ios::failbit ) << endl; cout << "eofbit " << ( ifs.rdstate( ) & ios::eofbit ) << endl; } std::cout << "Valeur deserialisee binary "<< f1 << std::endl ; ifs.close(); return ; } void test_text (float & f) { std::ofstream ofs("val.txt"); boost::archive::text_oarchive oa(ofs); oa << f ; ofs.close(); std::cout << "Valeur serialisee Texte " << f << std::endl ; std::ifstream ifs("val.txt"); boost::archive::text_iarchive ia(ifs); float f2 ; ia >> f2; std::cout << "Valeur deserialisee Texte "<< f2 << std::endl ; ifs.close(); return ; } void test_xml (float & f) { std::ofstream ofs("val.xml"); boost::archive::xml_oarchive oa(ofs); oa << BOOST_SERIALIZATION_NVP(f) ; ofs.close(); std::cout << "Valeur serialisee Xml " << f << std::endl ; std::ifstream ifs("val.xml"); boost::archive::xml_iarchive ia(ifs); float f2 ; ia >> BOOST_SERIALIZATION_NVP(f2); std::cout << "Valeur deserialisee Xml "<< f2 << std::endl ; ifs.close(); return ; } int main (int argc, const char * argv[]) { float f1 = (float)2.411667 ; test_text(f1); test_xml(f1); test_binary(f1); return 0; }