|
Boost Users : |
Subject: [Boost-users] Serialization of boost::posix_time::ptime
From: Archie14 (admin_at_[hidden])
Date: 2009-06-12 17:52:51
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();
}
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net