Serialization of boost::posix_time::ptime
I am saving and restoring thousand ptimes and integers. If I am saving/restoring only ptimes - everything works. If I add integers to it - it breaks. Code to reproduce the problem is shown below. I will appreciate any help in solving the problem. void test() { boost::gregorian::date ofdate = boost::gregorian::day_clock::local_day(); boost::posix_time::ptime dt = boost::posix_time::second_clock().local_time(); dt = boost::posix_time::ptime(ofdate, dt.time_of_day()); boost::posix_time::ptime dtcurrent = dt; std::ofstream fst; fst.open(L"c:\\test.test", std::ios_base::binary); for (int i = 0; i<1000;i++) { fst.write((char*)&i, sizeof(int)); dtcurrent += boost::posix_time::time_duration(0,0, i); fst<<dtcurrent; } fst.close(); std::ifstream ist(L"c:\\test.test", std::ios_base::binary); dtcurrent = dt; for (int i = 0; i<1000;i++) { dtcurrent += boost::posix_time::time_duration(0,0, i); int j = -1; ist.read((char*)&j, sizeof(int)); boost::posix_time::ptime dt1; ist>>dt1; assert ( (dtcurrent == dt1) && (j == i) ); } ist.close(); }
participants (1)
-
Archie14