#include #include #include #include using namespace std; class SaveData { public: float a; unsigned int b; public: template void serialize(Archive & ar, const unsigned int version) { ar & a; ar & b; } SaveData() : a(INFINITY), b(0) {} }; int main() { unsigned long counter(0); float theFloat; try { for(;;++counter) { //generate data to save SaveData dataToSave; if(counter == 0) theFloat = 0; if(counter == 1) theFloat = 1; if(counter == 2) theFloat = INFINITY; if(counter == 3) { theFloat = sqrt (-1); //NaN } dataToSave.a = theFloat; cout << theFloat << endl; //save dataToSave stringstream ss; boost::archive::text_oarchive oa(ss); oa << dataToSave; //restore data to dataToLoad SaveData dataToLoad; boost::archive::text_iarchive ia(ss); ia >> dataToLoad; } } catch(exception& e) { cout << "\r\nCrashed on float " << theFloat << endl; cout << "Error: " << e.what() << endl; } return 0; }